我可以将json数据返回到像二维数组一样形成的视图吗? [英] Can I return the json data to the view which formate like a two-dimensional array?
本文介绍了我可以将json数据返回到像二维数组一样形成的视图吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在视图中我想得到这样的json数据:
In the view I want to get the json data like this:
[{"name":"NewWork",
"data":[{"\/Date(1398787200000)\/",196},
{"\/Date(1398009600000)\/",62},
{"\/Date(1397836800000)\/",65}]
},
{"name":"BeiJing",
"data":[{"\/Date(1398787200000)\/",106},
{"\/Date(1398700800000)\/",100},
{"\/Date(1398441600000)\/",61},
{"\/Date(1398355200000)\/",86}]
}]
所以在控制器中我定义了这样的类,并返回`List< viewmodelcitydata>`但返回数据格式不是我想要的。如何更改控制器ViewModelCityData?另外一个问题,在视图中我的json`data`需要按`X`排序,如果我在控制器中对它们进行排序,为什么它们没有命令在视图中?我必须再次对它们进行排序在视图中。
So in the controller I define the class like these,and return `List<viewmodelcitydata>` but the return data format is not what I want.How can I change the controller ViewModelCityData?And the other question,in the view my json `data` need to be order by `X`,if I sort them in the controller,why do they not order in the view?I have to sort them again in the view.
public class ViewModelCityData
{
public string name { get; set; }
public List<Point> data { get; set; }
}
public class Point
{
public DateTime X { get; set; }
public int Y { get; set; }
}
[{"name":"NewWork",
"data":[{"X":"\/Date(1398787200000)\/","Y":196},
{"X":"\/Date(1398009600000)\/","Y":62},
{"X":"\/Date(1397836800000)\/","Y":65}]
},
{"name":"BeiJing",
"data":[{"X":"\/Date(1398787200000)\/","Y":106},
{"X":"\/Date(1398700800000)\/","Y":100},
{"X":"\/Date(1398441600000)\/","Y":61},
{"X":"\/Date(1398355200000)\/","Y":86}]}]
推荐答案
这篇关于我可以将json数据返回到像二维数组一样形成的视图吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文