Angular,访问具有特殊字符的JSON元素

时间:2018-03-26 10:06:28

标签: json angular

我有json String如下,如何访问元素,

我试过了 responsePdiJson.xs:schema或responsePdiJson.'xs:schema'none works

Cloning into 'mango'...
remote: Counting objects: 61211, done.
remote: Compressing objects: 100% (180/180), done.
remote: Total 61211 (delta 92), reused 0 (delta 0)
Receiving objects: 100% (61211/61211), 196.57 MiB | 11.05 MiB/s, done.
Resolving deltas: 100% (40317/40317), done.
fatal: cannot create directory at 'app/Events/eloquent.created: App': 
Invalid argument
warning: Clone succeeded, but checkout failed.
You can inspect what was checked out with 'git status'
and retry the checkout with 'git checkout -f HEAD'

下面是我用来将xml转换为JSON

的函数
{  
   "xs:schema":{  
      "$":{  
         "elementFormDefault":"qualified",
         "targetNamespace":"urn:eas-samples:en:xsd:phonecalls.1.0",
         "version":"1.0",
         "xmlns:xs":"http://www.w3.org/2001/XMLSchema"
      },
      "xs:element":[  
         {  
            "$":{  
               "name":"Calls"
            },
            "xs:complexType":[  
               {  
                  "xs:sequence":[  
                     {  
                        "$":{  
                           "maxOccurs":"unbounded"
                        },
                        "xs:element":[  
                           {  
                              "$":{  
                                 "name":"Call"
                              },

1 个答案:

答案 0 :(得分:2)

您可以使用

访问它
responsePdiJson["xs:schema"]; 

<强>样本

var myObj = {
  "xs:schema": {
    "$": {
      "elementFormDefault": "qualified",
      "targetNamespace": "urn:eas-samples:en:xsd:phonecalls.1.0",
      "version": "1.0",
      "xmlns:xs": "http://www.w3.org/2001/XMLSchema"
    },
    "xs:element": [
      {
        "$": {
          "name": "Calls"
        }
      }
    ]
  }
};

console.log(myObj["xs:schema"]);