0

I get some json data form the web which is like:

[{
  "pk": 1,
  "model": "stock.item",
  "fields": {
    "style": "f/s",
    "name": "shirt",
    "color": "red",
    "sync": 1,
    "fabric_code": "0012",
    "item_code": "001",
    "size": "34"
  }
}, {
  "pk": 2,
  "model": "stock.item",
  "fields": {
    "style": "febric",
    "name": "Trouser",
    "color": "red",
    "sync": 1,
    "fabric_code": "fabric code",
    "item_code": "0123",
    "size": "44"
  }
}]

How can i use it in the C# winforms desktop application. I already get this data in the form of string.
Edit:
I also try to use this way..

JavaScriptSerializer ss = new JavaScriptSerializer();
object itm = ss.DeserializeObject(responseFromServer);

It returns 'System.Object[]' but i also dont know that how i can use this.
All types of answer are welcome.

0

2 Answers 2

0

I think what your after is JSON.NET

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

Comments

0

The documentation for JavaScriptSerializer specifies that for your purpose you should use Json.NET instead.

However, if you prefer to continue to use JavaScriptSerializer you need to do the following:

JavaScriptSerializer ss = new JavaScriptSerializer();
var itm = ss.DeserializeObject(responseFromServer);

The StackOverflow thread difference-between-var-and-object-in-c-sharp describes how using var implicitly types the variable, so that it's easier to work with, where-as your code uses object, which strongly types it to an object.

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.