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" }]

4
  • 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? Commented May 25, 2017 at 6:33
  • Click here to see an example to deserialize JSON into an object. Commented May 25, 2017 at 7:02
  • I use var content = await response.Content.ReadAsStringAsync(); ? = JsonConvert.DeserializeObject<Library>(content); I am not sure about ? part. Commented May 25, 2017 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 Commented May 25, 2017 at 21:00

2 Answers 2

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}');

Sign up to request clarification or add additional context in comments.

1 Comment

This question is about C#, not JS.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.