解析複雜的JSON對象的最佳做法是什麼?在這種情況下,它將發佈到控制器操作?在C中解析嵌套和複雜的JSON響應#
由於發件人會隨着時間改變JSON的結構,所以預先創建一個模型類是脆弱的。
控制器
// POST api/values
public void Post([FromBody] AdminNotesModel value)
{
// do something with JSON...
}
有效載荷例如
{
"type": "notification_event",
"app_id": "cl00zu9g",
"data": {
"type": "notification_event_data",
"item": {
"type": "conversation",
"id": "7594189485",
"created_at": 1483576126,
"updated_at": 1483650387,
"user": {
"type": "user",
"id": "586d933eb76086661e49c991",
"user_id": "83c3224b-45b2-4f7d-a978-40c836564658",
"name": "Byrne MichaelaS",
"email": "[email protected]"
},
"assignee": {
"type": "admin",
"id": "848395",
"name": "Linda",
"email": "[email protected]"
},
"conversation_message": {
"type": "conversation_message",
"id": "69270153",
"subject": "<p>Summer internship possibilities </p>",
"body": "<p>Hello,</p><p>My name is Joe Foo. </p><p>Thanks for your time and please let me know if this might be a possibility.</p>",
"author": {
"type": "user",
"id": "586d933eb76086661e49c991"
},
"attachments": []
},
"conversation_parts": {
"type": "conversation_part.list",
"conversation_parts": [
{
"type": "conversation_part",
"id": "416288171",
"part_type": "note",
"body": "<p>Sent to Vicki</p>",
"created_at": 1483650387,
"updated_at": 1483650387,
"notified_at": 0,
"assigned_to": null,
"author": {
"type": "admin",
"id": "848395",
"name": "Linda"
},
"attachments": [],
"external_id": null
}
],
"total_count": 1
},
"open": true,
"read": true,
"metadata": {},
"tags": {
"type": "tag.list",
"tags": []
},
"links": {
"conversation_web": "https://app.intercom.io/a/apps/"
}
}
},
"links": {},
"id": "notif_d2e41790-d38a-11e6-b063-f9334405d60a",
"topic": "conversation.admin.noted",
"delivery_status": "retry",
"delivery_attempts": 2,
"delivered_at": 0,
"first_sent_at": 1483650448,
"created_at": 1483650387,
"self": null
}
您可以接受一個對象作爲參數: '公共無效後([FromBody] obj對象){ \\你想用OBJ 什麼都}' – DomeTune