Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- parsing by Linq to JSON
- {"SearchResults":[{"PageCount":"1"},
- {"SEARCHVAL":"Result","CATEGORY":"Category1","X":"1","Y":"2"},
- {"SEARCHVAL":"AnotherResult","CATEGORY":"Category1","X":"2","Y":"2"}]}
- WebClient client = new WebClient();
- client.OpenReadCompleted +=
- new OpenReadCompletedEventHandler(client_OpenReadCompleted);
- client.OpenReadAsync(uri);
- JsonObject searchResults = (JsonObject)JsonValue.Load(e.Result);
- public class SearchResult
- {
- public string SearchValue {get; set;}
- public string Category {get; set;}
- public string X {get; set;}
- public string Y {get; set;}
- }
- var resultList = ((JsonArray)searchResults["SearchResults"])
- .OfType<JsonObject>()
- .Where(o => o.ContainsKey("SEARCHVAL"))
- .Select(o => new SearchResult() {
- SearchValue = o["SEARCHVALUE"],
- Category = o["CATEGORY"].
- X = o["X"],
- Y = o["Y"]
- }).ToList();
Add Comment
Please, Sign In to add comment