I have created JSON file which contains like as below
[
{
"points": [
{
"index": 0,
"AccX": -0.0699
},
{
"index": 1,
"AccX": -0.0605
},
"name": "AccX",
"Calibration": [
{
"Bias": "0.0",
"Gain": "1.0"
}
],
"MinAttr": -0.0028,
"MaxAttr": 3.1936
},
{
"points": [
{
"index": 0,
"AccY": -0.0699
},
{
"index": 1,
"AccY": -0.0605
},
"name": "AccY",
"Calibration": [
{
"Bias": "0.0",
"Gain": "1.0"
}
],
"MinAttr": -0.0028,
"MaxAttr": 3.1936
}
]
My Model class to get the object for this json data is -
public class Points
{
public int index { get; set; }
public int AccX { get; set; }
public int AccY { get; set; }
public int AccZ { get; set; }
public int gyroZ { get; set; }
}
public class RootObject
{
public List<Points> point { get; set; }
}
in control class i have used like this,
var ReadJson = System.IO.File.ReadAllText(Server.MapPath(@"~/App_Data/chartData.json"));
JavaScriptSerializer ser = new JavaScriptSerializer();
ser.MaxJsonLength = int.MaxValue;
RootObject json = ser.Deserialize<RootObject>(ReadJson);
foreach (var item in json.point)
{
ViewBag.Name = item.index;
ViewBag.ShortText = item.AccX;
}
return View();
I hope i am doing this wrong i need to deserialize the json data and return data...
how to achieve this?
>(ReadJson)` helps?
– Rajshekar Reddy Oct 28 '16 at 08:20