为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

C#
扬帆大鱼 2022-08-20 17:33:36
我有一个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"    }  ]}"
查看完整描述

2 回答

?
烙印99

TA贡献1829条经验 获得超13个赞

您可以使用解构赋值


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} = obj


console.log(getEmailBasicData,getEmailDocumentData,getEmailParticipantData)


查看完整回答
反对 回复 2022-08-20
?
动漫人物

TA贡献1815条经验 获得超10个赞

使用运算符访问.


var a={

  "$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": "Md Rashedul Islam",

      "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"

    }

  ]

}

var basic=a.getEmailBasicData;

var doc=a.getEmailDocumentData;

var participants=a.getEmailParticipantData;

console.log(basic);

console.log(doc);

console.log(participants);


查看完整回答
反对 回复 2022-08-20
  • 2 回答
  • 0 关注
  • 264 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信