alfah
alfah

Reputation: 2085

Parse Json using Windows.Data.Json in Windows 8 C#

This is the json string that I want to parse. Im using the default Json functions available in Windows 8

JSON value:

"{\"updated_at\":1405482225,\"settings\":{\"conception_mode\":1,\"app_lock_string\":\"\",\"user_cycle_length\":21,\"week_starts_monday\":1}}"

My sample code:

 JsonObject test1 = JsonObject.Parse(received);
 var timestamp = test1.GetNamedValue("updated_at").GetNumber();
 settingsTimestamp = (long)(Convert.ToDouble(timestamp));

 string settingString = test1.GetNamedValue("settings").GetString();//ERROR
 JsonObject settingsVal = JsonObject.Parse(settingString);

I get the "updated_at" value but when I try to retrieve "settings", it is throwing exception saying, it is not a string.

For windows phone, I have done using JSON.NET library, so things were a little easier. How do I parse this in Windows8

Upvotes: 0

Views: 2380

Answers (1)

Sascha
Sascha

Reputation: 10347

settings is a JSON object. So you can use GetObject directly:

JsonObject settingsVal = test1.GetNamedValue( "settings" ).GetObject();

Upvotes: 2

Related Questions