AngularJS中的JSON解析

JSON Parse in AngularJS

本文关键字:解析 JSON 中的 AngularJS      更新时间:2023-09-26

我有一个JSON对象从服务器返回。

{
  "SOAP-ENV:Envelope": {
    "SOAP-ENV:Body": {
      "ADDWEBSOperationResponse": {
        "Num1": 10,
        "Result": 20,
        "Num2": 10,
        "xmlns": "http://www.**.**.Response.com"
      }
    },
    "xmlns:SOAP-ENV": "http://schemas.xmlsoap.org/soap/envelope/",
    "xmlns:soapenv": "http://schemas.xmlsoap.org/soap/envelope/",
    "xmlns:add": "http://www.**.**.Request.com"
  }
}

我想在我的页面中打印Result。我正在尝试data.Result,但它没有显示值。

使用bracket notation,因为它对于非标识符安全字符特别有用,也可以用于访问您可能事先不知道的密钥

data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"]["Result"]

试试

data['SOAP-ENV:Envelope']['SOAP-ENV:Body']['ADDWEBSOperationResponse'].Result

我应该

data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"].Result

你需要遵循层次结构。

JSFIDDLE

data["SOAP-ENV:Envelope"]["SOAP-ENV:Body"]["ADDWEBSOperationResponse"].Result