1
我正在连接来自c#的REST
api。我有Json
响应与几个不同名称的错误对象,但所有对象具有相同的变量: 标题, 消息和显示。我有JSon响应具有不同名称的对象,但所有对象具有相同的变量
对于API(REST)的每个请求,对象数都会变化,响应中的对象名称根据请求而不同。但每个错误中的变量都与上面相同。
我从这个响应中得到的信息只是消息文本,但如果我得到错误对象列表,我就可以通过错误消息读取它。
这里是JSON响应:
{
"errors": {
"missingparameter_general_paymenttype": {
"title": "",
"message": "You must enter 'general_paymenttype'.",
"display": ""
},
"missingparameter_contact_title": {
"title": "",
"message": "You must enter 'contact_title'.",
"display": ""
},
"missingparameter_contact_firstname": {
"title": "",
"message": "You must enter 'contact_firstname'.",
"display": ""
},
"missingparameter_contact_lastname": {
"title": "",
"message": "You must enter 'contact_lastname'.",
"display": ""
},
"missingparameter_contact_email": {
"title": "",
"message": "You must enter 'contact_email'.",
"display": ""
},
"missingparameter_contact_telephone": {
"title": "",
"message": "You must enter 'contact_telephone'.",
"display": ""
},
"invalidparameter_pricing_currency": {
"title": "",
"message": "Invalid value for 'pricing_currency'.",
"display": ""
},
"missingparameter_pricing_saleprice": {
"title": "",
"message": "You must enter 'pricing_saleprice'.",
"display": ""
},
"missingparameter_transfers": {
"title": "",
"message": "You must enter 'transfers'.",
"display": ""
}
}
}
'Newtonsoft.Json.JsonConvert。 DeserializeObject>(jsonStr)'当然,您必须定义一个类来包含字典 –
是否要将json转换为c#对象? – gypsyCoder
是@gypsyCoder – nicejani80