Guest User

Untitled

a guest
Aug 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. parsing by Linq to JSON
  2. {"SearchResults":[{"PageCount":"1"},
  3. {"SEARCHVAL":"Result","CATEGORY":"Category1","X":"1","Y":"2"},
  4. {"SEARCHVAL":"AnotherResult","CATEGORY":"Category1","X":"2","Y":"2"}]}
  5.  
  6. WebClient client = new WebClient();
  7. client.OpenReadCompleted +=
  8. new OpenReadCompletedEventHandler(client_OpenReadCompleted);
  9. client.OpenReadAsync(uri);
  10.  
  11. JsonObject searchResults = (JsonObject)JsonValue.Load(e.Result);
  12.  
  13. public class SearchResult
  14. {
  15. public string SearchValue {get; set;}
  16. public string Category {get; set;}
  17. public string X {get; set;}
  18. public string Y {get; set;}
  19. }
  20.  
  21. var resultList = ((JsonArray)searchResults["SearchResults"])
  22. .OfType<JsonObject>()
  23. .Where(o => o.ContainsKey("SEARCHVAL"))
  24. .Select(o => new SearchResult() {
  25. SearchValue = o["SEARCHVALUE"],
  26. Category = o["CATEGORY"].
  27. X = o["X"],
  28. Y = o["Y"]
  29. }).ToList();
Add Comment
Please, Sign In to add comment