SVI
SVI

Reputation: 1651

Fetch values from a JSON response in c#

I have a following JSON repsonse from a API.

"{\"status\":\"True\", \"itemID\":\"201\"}".

On client side, how do I get values from status and itemID. I am NOT working in javascript. This is a c# class.

Upvotes: 1

Views: 207

Answers (2)

Sergey Gavruk
Sergey Gavruk

Reputation: 3558

Use library to work with json. For example, JSON.NET

Here is example:

string json = @"{
  ""Name"": ""Apple"",
  ""Expiry"": new Date(1230422400000),
  ""Price"": 3.99,
  ""Sizes"": [
    ""Small"",
    ""Medium"",
    ""Large""
  ]
}";

JObject o = JObject.Parse(json);

string name = (string)o["Name"];
// Apple

JArray sizes = (JArray)o["Sizes"];

string smallest = (string)sizes[0];
// Small

Upvotes: 1

Related Questions