Reputation: 4266
I'm searching for a way to retrieve data (formatted in json) from an API and parse them.
I really want to use the code both for android and for IOS. I already saw examples but they didn't work for both platforms.
If you can provide me examples for connection, retrieving and for json, it is the best for me because I didn't find great docs about cross-platform (quite simple) implementation.
Comments Welcome !
Thanks in advance!
Upvotes: 3
Views: 5660
Reputation: 2095
Instead of using nuget to download Newtonsoft, you need to download it from here:http://components.xamarin.com/view/json.net/
Upvotes: 1
Reputation: 11040
I've used Newtonsoft's json library in a monotouch solution
Find the source code here.
As far as retrieving the data - that depends on your API, I suspect it's a web API with HTTP calls? If that's the case you can further elaborate on this, obviously exception handling and threading is up to you:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create (url);
...
request.BeginGetResponse ((r) =>
{
string res = null;
using (StreamReader srd = new StreamReader(response.GetResponseStream())) {
res = srd.ReadToEnd ();
}
T jres = Newtonsoft.Json.JsonConvert.DeserializeObject<T> (res);
}, null);
Upvotes: 4