如何从jsonresult读取数据 [英] How to read data from a jsonresult
本文介绍了如何从jsonresult读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从jsonResult读取数据?
我的Jsonresout返回数据{}
< pre lang =C#> {total = 9 ,rows = {System.Collections.Generic.List<<> f__AnonymousType9< int, int ?, string , string , int ?, string>>}}
a行列表,
如何用JS读取这个?
greate
我尝试了什么:
使用alert(d.rows.length)时,它警告(0)
如何获取json中的数据
解决方案
它看起来代码中有一个JSON语法。 />
JSON的一个常见用途是从Web服务器读取数据,并在网页中显示数据,JSON数据作为名称/值对写入。数据集括号表示数组
这里是基本语法
test:[
{ fname : abc, lname: xxx},
{ fname: pqr, lname: yyy},
{ fname: lmn ,lname: zzz}
]
// 阅读以上JSON我们需要以下javascript
var obj = JSON .parse(text);
document .getElementById( lbl1).innerHTML =
obj.employees [ 1 ]。firstName + < span class =code-string> + obj.employees [ 1 ]。lastName;
只需使用这个
return Json(result.ToList(),JsonRequestBehavior。 AllowGet);
alert(d.length); // 读取计数
How to Read Data from a jsonResult?
My Jsonresout returns data{}
{ total = 9, rows = {System.Collections.Generic.List<<>f__AnonymousType9<int, int?, string, string, int?, string>>} }
a list in rows,
how can I read this using JS?
greate
What I have tried:
when using alert(d.rows.length) , it alert(0)
how can I get the data in the json
解决方案
It looks there is a JSON syntax in your code.
A common use of JSON is to read data from a web server, and display the data in a web page, JSON data is written as name/value pairs. Curly brackets indicates objects and square for Array
here is basic syntax
"test":[ {"fname":"abc", "lname":"xxx"}, {"fname":"pqr", "lname":"yyy"}, {"fname":"lmn", "lname":"zzz"} ] //to read above JSON we need below javascript var obj = JSON.parse(text); document.getElementById("lbl1").innerHTML = obj.employees[1].firstName + " " + obj.employees[1].lastName;
just use this
return Json(result.ToList(), JsonRequestBehavior.AllowGet);
alert(d.length);//to read the count
这篇关于如何从jsonresult读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文