I have the following JSON data containing multiple sub array, Any suggestion how can Deserialize this and print on my page.
NEXT STEP
: After this, I need to insert this data in SQL using bulk copy features.
C# Code
collect mydata= new JavaScriptSerializer().Deserialize<collect >(json);
foreach (var item in mydata.results)
{
context.Response.Write(item.newPrice + item.pName);
}
public class collect
{
public List<collection1> results { get; set; }
}
public class collection1
{
public List<data> collection1 { get; set; }
}
public class data
{
public string newPrice { get; set; }
public string pName { get; set; }
}
JSON Array :
{
"name": "Test 1",
"count": 3,
"version": 2,
"lastsuccess": "Thu Oct 09 2014 05:42:17 GMT+0000 (UTC)",
"results": {
"collection1": [
{
"newPrice": "12787",
"pName": "Sony Xperia M Dual Black"
},
{
"newPrice": "24999",
"pName": "LG Google Nexus 5 16 GB (Black)"
}
]
}
}
To answer your question regarding how to de serialize the JSON here is a solution... I am not sure what you mean by "Print on my page" as your question does not put that into any context however...
I used http://json2csharp.com to create the poco classes below...
public class Collection1
{
public string newPrice { get; set; }
public string pName { get; set; }
}
public class Results
{
public List<Collection1> collection1 { get; set; }
}
public class RootObject
{
public string name { get; set; }
public int count { get; set; }
public int version { get; set; }
public string lastsuccess { get; set; }
public Results results { get; set; }
}
Then the following code will deserialize the JSON to C#...
RootObject myData = new JavaScriptSerializer().Deserialize<RootObject>(json);
You can now do with it as you please, in terms of your bulk insert... thats another question really so please start a new one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.