What’s the best way to parse Json file in WinRT/UWP application using C#?

csharp
winrt
uwp

(Sine) #1

Hi,

What is the best way to parse Json files and text in WinRT/UWP application?
I need to read & write Json files in my UWP Windows Store App.


(Yay) #2

You can use Windows.Data.Json namespace to read/write & parse json files.

You can use the classes JsonValue & JsonObject like this:

JsonValue jsonValue = JsonValue.Parse(JsonString);
String PropertyValue = jsonValue.GetObject().GetNamedString("KeyName");

JsonString: Being the JSON string to parse (it can be some string you read from an external file).
KeyName: The JSON property key name.
PropertyValue: The value of the property with the given key name.