Question

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 ?

Was it helpful?

Solution

If you want to serialize the response as a JsonObject you should use JsonObject.Parse(string) or JsonObject.TryParse(string, out JsonObject) methods.

OTHER TIPS

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);

Newtonsoft's JSON API

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top