Reputation:
I get a response string from an API by using this code :
HttpResponseMessage response = await client.GetAsync(url);
string responseText = await response.Content.ReadAsStringAsync();
However I'm unable to find out how to initialize a JsonObject since in .NET for WinRT the constructor JsonObject() doesn't take any arguments. For memory I could have made like that in the "regular" .NET Framework :
JsonObject root = new JsonObject(responseText);
What I've missed ?
Upvotes: 1
Views: 2982
Reputation: 13019
If you want to serialize the response as a JsonObject
you should use JsonObject.Parse(string)
or JsonObject.TryParse(string, out JsonObject)
methods.
Upvotes: 3
Reputation: 690
Unless you are truly needing to parse/traverse a JSON encoded string, perhaps all you need to is deserialize it. Here are Microsoft docs on doing that.
Deserialize JSON Encoded String
I personally like working with Newtonsoft's JSON API for this task.
MyObject obj = JsonConvert.DeserializeObject<MyObject>(jsonEncodedString);
Hope this helps.
Upvotes: 1