1

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.

skaffman
  • 398,947
  • 96
  • 818
  • 769
SVI
  • 1,631
  • 3
  • 22
  • 30

2 Answers2

1

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
Sergey Gavruk
  • 3,538
  • 2
  • 20
  • 31
0

Take a look at this nifty C# 4.0 implementation http://www.drowningintechnicaldebt.com/ShawnWeisfeld/archive/2010/08/22/using-c-4.0-and-dynamic-to-parse-json.aspx

kfuglsang
  • 2,385
  • 2
  • 21
  • 26