检索从WCF休息服务返回的JSON数据

时间:2012-10-05 14:38:42

标签: c# jquery json web

  

可能重复:
  How to get values of attributes from JSON using jQuery

我已使用jsonlint验证了json返回,并且它是有效的。作为一个简单的例子,

"JSONDataResult": "{ \"?xml\":{\"@version\":\"1.0\",\"@encoding\":\"utf-8\"},\"Root\":{\"Information\":{\"Error\":{\"ErrorNo\":\"0\",\"ErrorMsg\":null},\"Address\":{\"Address\":[{\"@AddressID\":\"1232233\",\"@Sequence\":\"1\",\"@Description\":\"Company, Building, 11 Street, County, City\"}

...此处有更多数据和所有正确的标签等。

使用以下方法返回上述数据结构,但我无法将其分解为其组件。

      $.getJSON('http://localhost/WcfRestService/RestServiceImpl.svc/json/mypostcode', 
       function (data) {
          //tried all sorts of variations of this sort of thing: data.Root.Information.Address.Address[0]
    });

任何想法都会受到赞赏。

1 个答案:

答案 0 :(得分:0)

我会试着找出收到的json结构真正的样子。只需将数据调试到控制台或写一个警告显示给您。我的猜测是你需要打电话:

data.JSONDataResult.Root...

data.d.JSONDataResult.Root...

访问“Root”属性。

相关问题