0

I have a JSON file like below and I want to desterilize it to JSON Object how can I do it ? Thanks

{ "TOTAL": 2, "PRODUCTS": [ { "CODE": "T55", "PRICE": 59.95, "DESCRIPTION": "Ok" }, { "CODE": "T75", "PRICE": 99.95, "DESCRIPTION": "Not OK" }]

Fattaneh
  • 143
  • 1
  • 4
  • 13
  • Did you write any code for this So far ? Did you try expiring newtonsoft.json library and how to use it? Did you try using the default json serialization classes available in .net? – Chetan May 25 '17 at 06:33
  • Click [here](https://stackoverflow.com/questions/8249454/how-do-deserialize-this-json-into-an-object) to see an example to deserialize JSON into an object. – Ahaliya May 25 '17 at 07:02
  • I use var content = await response.Content.ReadAsStringAsync(); ? = JsonConvert.DeserializeObject(content); I am not sure about ? part. – Fattaneh May 25 '17 at 20:56
  • the content is like this "{\"TOTAL\":177,\"PRODUCTS\":[{\"CODE\":\"T55-2A\",\"PRICE\":59.9500,\"NAME\":\"Arrive In Style\"},{\"CODE\":\"F1-231\",\"PRICE\":49.9500 and it is ok – Fattaneh May 25 '17 at 21:00

2 Answers2

0

You can refer this link for parsing from a file : Get a JSON file from URL and display

And

You can use : var obj = JSON.parse('{ "name":"Pawan", "age":24}');

Pawan Ratre
  • 41
  • 1
  • 6
0

Modern browsers support JSON.parse().

var json = [{
"TOTAL": 2,
 "PRODUCTS": [
{
  "CODE": "T55",
   "PRICE": 59.95,
  "DESCRIPTION": "Ok"
   },
{
  "CODE": "T75",
   "PRICE": 99.95,
  "DESCRIPTION": "Not OK"
}];

var arr_from_json = JSON.parse( json_string );

In browsers that don't, you can include the json2 library.

Ahaliya
  • 57
  • 1
  • 14