如何从包含多个对象数组的Json数据中提取多个对象数组?

我有一个Json数据,其中包含由mvc控制器发送的多个对象数组。我需要以不同的方式提取这些数组。我想要 getEmailBasicData array, getEmailParticipantData array, getEmailDocumentData array 单独进行 如何做到这一点?这是我的代码 -


"{

  "$id": "1",

  "getEmailBasicData": [

    {

      "$id": "2",

      "notificationId": 23,

      "subject": "final test",

      "message": "<p>this is body</p>\n",

      "sendStatus": -1,

      "lastSendTime": null

    },

    {

      "$id": "3",

      "notificationId": 24,

      "subject": "final subject",

      "message": "<p>final body</p>\n",

      "sendStatus": -1,

      "lastSendTime": null

    },

    {

      "$id": "12",

      "notificationId": 33,

      "subject": "Final Test",

      "message": "<p>Final body</p>\n",

      "sendStatus": -1,

      "lastSendTime": null

    }

  ],

  "getEmailParticipantData": [

    {

      "$id": "13",

      "id": 55,

      "notificationId": 23,

      "employeeId": -1,

      "name": "here is the name",

      "emailAddress": "whatever@gmail.com",

      "contactNo": null

    },

    {

      "$id": "14",

      "id": 56,

      "notificationId": 23,

      "employeeId": -1,

      "name": "another name",

      "emailAddress": "someone@gmail.com",

      "contactNo": null

    } ],

    "getEmailDocumentData": [

    {

      "$id": "36",

      "id": 40,

      "notificationId": 23,

      "docId": 1,

      "attachmentLocation": "1_1_50474603_2287746231437248_8529393497499762688_n.jpg"

    },

       {

      "$id": "46",

      "id": 50,

      "notificationId": 33,

      "docId": 1,

      "attachmentLocation": 

 "1_1_50474603_2287746231437248_8529393497499762688_n.jpg"

    }

  ]

}"


扬帆大鱼
浏览 363回答 2
2回答

烙印99

您可以使用解构赋值let obj = {"$id":"1","getEmailBasicData":[{"$id":"2","notificationId":23,"subject":"finaltest","message":"<p>thisisbody</p>\n","sendStatus":-1,"lastSendTime":null},{"$id":"3","notificationId":24,"subject":"finalsubject","message":"<p>finalbody</p>\n","sendStatus":-1,"lastSendTime":null},{"$id":"12","notificationId":33,"subject":"FinalTest","message":"<p>Finalbody</p>\n","sendStatus":-1,"lastSendTime":null}],"getEmailParticipantData":[{"$id":"13","id":55,"notificationId":23,"employeeId":-1,"name":"MdRashedulIslam","emailAddress":"rashed.cse08@gmail.com","contactNo":null},{"$id":"14","id":56,"notificationId":23,"employeeId":-1,"name":"Akash","emailAddress":"akash@ravensystemstld.com","contactNo":null}],"getEmailDocumentData":[{"$id":"36","id":40,"notificationId":23,"docId":1,"attachmentLocation":"1_1_50474603_2287746231437248_8529393497499762688_n.jpg"},{"$id":"46","id":50,"notificationId":33,"docId":1,"attachmentLocation":"1_1_50474603_2287746231437248_8529393497499762688_n.jpg"}]}const {getEmailBasicData,getEmailDocumentData,getEmailParticipantData} = objconsole.log(getEmailBasicData,getEmailDocumentData,getEmailParticipantData)

动漫人物

使用运算符访问.var a={&nbsp; "$id": "1",&nbsp; "getEmailBasicData": [&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; "$id": "2",&nbsp; &nbsp; &nbsp; "notificationId": 23,&nbsp; &nbsp; &nbsp; "subject": "final test",&nbsp; &nbsp; &nbsp; "message": "<p>this is body</p>\n",&nbsp; &nbsp; &nbsp; "sendStatus": -1,&nbsp; &nbsp; &nbsp; "lastSendTime": null&nbsp; &nbsp; },&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; "$id": "3",&nbsp; &nbsp; &nbsp; "notificationId": 24,&nbsp; &nbsp; &nbsp; "subject": "final subject",&nbsp; &nbsp; &nbsp; "message": "<p>final body</p>\n",&nbsp; &nbsp; &nbsp; "sendStatus": -1,&nbsp; &nbsp; &nbsp; "lastSendTime": null&nbsp; &nbsp; },&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; "$id": "12",&nbsp; &nbsp; &nbsp; "notificationId": 33,&nbsp; &nbsp; &nbsp; "subject": "Final Test",&nbsp; &nbsp; &nbsp; "message": "<p>Final body</p>\n",&nbsp; &nbsp; &nbsp; "sendStatus": -1,&nbsp; &nbsp; &nbsp; "lastSendTime": null&nbsp; &nbsp; }&nbsp; ],&nbsp; "getEmailParticipantData": [&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; "$id": "13",&nbsp; &nbsp; &nbsp; "id": 55,&nbsp; &nbsp; &nbsp; "notificationId": 23,&nbsp; &nbsp; &nbsp; "employeeId": -1,&nbsp; &nbsp; &nbsp; "name": "Md Rashedul Islam",&nbsp; &nbsp; &nbsp; "emailAddress": "rashed.cse08@gmail.com",&nbsp; &nbsp; &nbsp; "contactNo": null&nbsp; &nbsp; },&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; "$id": "14",&nbsp; &nbsp; &nbsp; "id": 56,&nbsp; &nbsp; &nbsp; "notificationId": 23,&nbsp; &nbsp; &nbsp; "employeeId": -1,&nbsp; &nbsp; &nbsp; "name": "Akash",&nbsp; &nbsp; &nbsp; "emailAddress": "akash@ravensystemstld.com",&nbsp; &nbsp; &nbsp; "contactNo": null&nbsp; &nbsp; } ],&nbsp; &nbsp; "getEmailDocumentData": [&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; "$id": "36",&nbsp; &nbsp; &nbsp; "id": 40,&nbsp; &nbsp; &nbsp; "notificationId": 23,&nbsp; &nbsp; &nbsp; "docId": 1,&nbsp; &nbsp; &nbsp; "attachmentLocation": "1_1_50474603_2287746231437248_8529393497499762688_n.jpg"&nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; &nbsp;{&nbsp; &nbsp; &nbsp; "$id": "46",&nbsp; &nbsp; &nbsp; "id": 50,&nbsp; &nbsp; &nbsp; "notificationId": 33,&nbsp; &nbsp; &nbsp; "docId": 1,&nbsp; &nbsp; &nbsp; "attachmentLocation":&nbsp;&nbsp;"1_1_50474603_2287746231437248_8529393497499762688_n.jpg"&nbsp; &nbsp; }&nbsp; ]}var basic=a.getEmailBasicData;var doc=a.getEmailDocumentData;var participants=a.getEmailParticipantData;console.log(basic);console.log(doc);console.log(participants);
打开App,查看更多内容
随时随地看视频慕课网APP