Parse JSON in WP7
Windows Phone 7 may be quite obsolete at this point, but since WP8 still runs WP7 apps, it is worth trying to make your apps backwards-compatible where possible.
Using Newtonsoft JSON.NET to parse JSON is a good option, but you have to get the right version, the latest version is only for Windows Phone 8. I found version 4.0.3 (40r3) worked for me.
Here is a brief example of how I used it:
public static void Search(string depart, string arrive, Action<JObject> callback)
{
var strUrl = “http://www.rome2rio.com/api/1.0/json/Search?key=xxxx&oName={0}&dName={1}”;
strUrl = string.Format(strUrl, depart, arrive);
WebClient wc = new WebClient();
wc.DownloadStringAsync(new Uri(strUrl), callback);
wc.DownloadStringCompleted += (sender, args) =>
{
var jo = JObject.Parse(args.Result);
callback(jo);
};
}
Of course, you need to use using Newtonsoft.Json.Linq;