【问题标题】:Retrieve JSON Data returned from WCF rest service [duplicate]检索从 WCF 休息服务返回的 JSON 数据 [重复]
【发布时间】:2012-10-05 14:38:42
【问题描述】:

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

我已经验证了 json 正在使用 jsonlint 返回并且它是有效的。举个简单的例子,

"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]
    });

任何想法将不胜感激。

【问题讨论】:

  • 当您粘贴的 JSON 无效:jsonformatter.curiousconcept.com
  • 你应该提供更多关于它的信息。
  • 我想从每个地址字段中获取地址。此刻没有快乐。
  • 你接受的this answer有什么问题?
  • 现在 json 是通过 wcf rest 服务而不是 http 处理程序返回的,它只是没有它。

标签: c# jquery json web


【解决方案1】:

我会尝试找出收到的 json 结构的真正样子。只需将 data 调试到控制台或编写一个向您显示它的警报。我的猜测是你需要打电话:

data.JSONDataResult.Root...

data.d.JSONDataResult.Root...

访问“根”属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-10
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多