-1

专家,

我有一个.netservice,它返回 json 数据,我使用代码提取了 json 数据

success: function (r) {
        var doclist = $.parseJSON(r.d);
        console.log(doclist);

我得到了这样的输出

{"status":{"status":"success","userid":"1"},"data":{"docId":9,"doc_name":"Array","file_name":"Admin/ch6_macro_processors.pdf","owneruser":1,"cat_id":1,"desctiption":"jkkkl","comments":"fghh","dept_id":1,"contype":"application/pdf","size":0,"rvwFlg":"application/pdf","right":"R"},"data":{"docId":10,"doc_name":"Image","file_name":"Admin/545765_427770260634015_1210695556_n.jpg","owneruser":1,"cat_id":1,"desctiption":"control so users can upload files on the site that i've built. The location I'm attempting to save t","comments":"control so users can upload files on the site that i've built. The location I'm attempting to save t","dept_id":1,"contype":"image/jpeg","size":127,"rvwFlg":"image/jpeg","right":"R"},"data":{"docId":9,"doc_name":"Array","file_name":"Admin/ch6_macro_processors.pdf","owneruser":1,"cat_id":1,"desctiption":"jkkkl","comments":"fghh","dept_id":1,"contype":"application/pdf","size":0,"rvwFlg":"application/pdf","right":"U"}} 

console.log(doclist.data["docId"]); retuns error 

“未捕获的类型错误:无法读取未定义的属性‘docId’”

如何阅读此 docId

我正在使用 Visual Studio 2010 和框架 3.5

问候,

Sivajith S.

4

1 回答 1

1

查看我的示例jsFiddle 示例

您的问题是您没有访问内部对象。假设 r 是 json 字符串。

var doclist = $.parseJSON(r.d); // Service wraps the data in r.d
console.log(doclist);
alert(docList.data.docId);
于 2013-05-15T22:17:00.053 回答