如何使用嵌套数组格式化 JSONArray

How to format JSONArray with nested arrays

我想访问我的 JSONArray 中的字段。 JSONArray 里面的嵌套括号很麻烦。我看不出这种格式如何成为可接受的 JSONArray return 值。当我尝试使用 getJSONObject() 访问字段(例如 "rethink3__Address__c")时出现 JSONException。

 [
   [
      {
         "attributes":{
            "type":"rethink3__Listing__c",
            "url":"\/services\/data\/v42.0\/sobjects\/rethink3__Listing__c\/a06m0000005OPb9AAG"
         },
         "rethink3__Address__c":null,
         "Alarm_Code__c":null,
         "rethink3__Bathrooms__c":0,
         "rethink3__Bedrooms__c":0,
         "rethink3__Size__c":0,
         "Lock_Box_Code__c":null,
         "Lock_Box_Location_Notes__c":null,
         "_soupEntryId":1,
         "_soupLastModifiedDate":1537657104801
      }
   ],
   [
      {
         "attributes":{
            "type":"rethink3__Listing__c",
            "url":"\/services\/data\/v42.0\/sobjects\/rethink3__Listing__c\/a06m0000005OPb9AAG"
         },
         "rethink3__Address__c":null,
         "Alarm_Code__c":null,
         "rethink3__Bathrooms__c":0,
         "rethink3__Bedrooms__c":0,
         "rethink3__Size__c":0,
         "Lock_Box_Code__c":null,
         "Lock_Box_Location_Notes__c":null,
         "_soupEntryId":1,
         "_soupLastModifiedDate":1537657104801
      }
   ]
]

一个 [] = json 数组和 {} = json 对象。所以试试这个。

let myArray = [
    [
        {
            "attributes":{
                "type":"rethink3__Listing__c",
                "url":"\/services\/data\/v42.0\/sobjects\/rethink3__Listing__c\/a06m0000005OPb9AAG"
            },
            "rethink3__Address__c":null,
            "Alarm_Code__c":null,
            "rethink3__Bathrooms__c":0,
            "rethink3__Bedrooms__c":0,
            "rethink3__Size__c":0,
            "Lock_Box_Code__c":null,
            "Lock_Box_Location_Notes__c":null,
            "_soupEntryId":1,
            "_soupLastModifiedDate":1537657104801
        }
    ],
    [
        {
            "attributes":{
                "type":"rethink3__Listing__c",
                "url":"\/services\/data\/v42.0\/sobjects\/rethink3__Listing__c\/a06m0000005OPb9AAG"
            },
            "rethink3__Address__c":null,
            "Alarm_Code__c":null,
            "rethink3__Bathrooms__c":0,
            "rethink3__Bedrooms__c":0,
            "rethink3__Size__c":0,
            "Lock_Box_Code__c":null,
            "Lock_Box_Location_Notes__c":null,
            "_soupEntryId":1,
            "_soupLastModifiedDate":1537657104801
        }
    ]
];

myArray.forEach((myNestedArray)=>{
    let obj = myNestedArray[0]
    console.log(obj.attributes.type);
    console.log(obj._soupLastModifiedDate);
})