Hi sir,
I Need json code to get both the array and nonarray values like below. Please give me the code to learn. I tried one code but i am getting only array values, i dont know how to get both the array and non array values. Kindly give me the solution for this problem.
{
"products": [
{
"pid": "1",
"name": "iPhone 4S",
"price": "300.00",
"created_at": "2012-04-29 02:04:02",
"updated_at": "0000-00-00 00:00:00"
},
{
"pid": "2",
"name": "Macbook Pro",
"price": "600.00",
"created_at": "2012-04-29 02:04:51",
"updated_at": "0000-00-00 00:00:00"
},
{
"pid": "3",
"name": "Macbook Air",
"price": "800.00",
"created_at": "2012-04-29 02:05:57",
"updated_at": "0000-00-00 00:00:00"
},
{
"pid": "4",
"name": "OS X Lion",
"price": "100.00",
"created_at": "2012-04-29 02:07:14",
"updated_at": "0000-00-00 00:00:00"
}
],
"success": 1
}
Loading
Ring ZhongPosted Oct 25, 2013, 4:00 AM
http://www.codeproject.com/Questions/673413/Need-json-code-to-get-both-the-array-and-nonarray
http://forums.asp.net/t/1945822.aspxNeed+json+code+to+get+both+the+array+and+nonarray+values
hope it helps
Jaganathan BantheswaranPosted Oct 25, 2013, 2:02 AM
1) if you have object which you want to convert as json,
string jsonOfTest = Newtonsoft.Json.JsonConvert.SerializeObject(test);
or
string jsonString = new JavaScriptSerializer().Serialize(test);
2) If you dont have the respective object, use ExpandoObject.
dynamic test = new ExpandoObject();
test.x = "xvalue";
test.y = DateTime.Now;
test.arr = new List
string jsonOfTest = Newtonsoft.Json.JsonConvert.SerializeObject(test);
or
string jsonString = new JavaScriptSerializer().Serialize(test);
Prabu SparkPosted Oct 25, 2013, 1:48 AM
Jaganathan BantheswaranPosted Oct 25, 2013, 1:43 AM
In the example you have given, could access the array as well as nonarray value success.
I dont what is your problem here? You want to generate this json using C#?