2012-10-05 59 views
-1

可能重複:
How to get values of attributes from JSON using jQuery檢索WCF休息服務JSON數據返回

我已經使用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] 
    }); 

任何想法將不勝感激。

+0

粘貼時無效JSON:http://jsonformatter.curiousconcept.com/ –

+0

它是json的一部分 – user835440

+0

您應該提供更多關於它的信息。 –

回答

0

我會試着找出接收的json結構是什麼樣子。只需調試數據到控制檯或寫一個警報顯示給你。我的猜測是,你需要調用:

data.JSONDataResult.Root...

data.d.JSONDataResult.Root...

訪問 '根' 屬性。