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.

Mickael Lherminez
  • 679
  • 1
  • 10
  • 29
qulzam
  • 315
  • 2
  • 9
  • 20

2 Answers2

0

I think what your after is JSON.NET

Razor
  • 17,271
  • 25
  • 91
  • 138
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.

EtherDragon
  • 2,679
  • 1
  • 18
  • 24