我正在使用asp.net mvc-5 Web应用程序,我正在使用json.net来处理json对象并将其发布回外部API。
现在json对象现在如下: -
{
"operation":{
"Detail":{
"RESOURCENAME":"test123",
"ACCOUNTNAME":"admin",
"RESOURCETYPE":"windows",
"PASSWORD":"Test2Test2",
"NOTES":"From TMS",
"RESOURCEURL":null,
"RESOURCECUSTOMFIELD":{
"CUSTOMLABEL":"Asset Tag",
"CUSTOMVALUE":"C100100"
}
}
}
}
但我会从API中得到一个错误,即json的格式不正确。现在基于API文档,传递的json需要采用以下格式: -
curl -X POST -k -H "Content-Type: text/json"
'https://192.168.39.29:7272/restapi/json/v1/resources?AUTHTOKEN=B9A1809A-5BF
7-4459-9ED2-8D4F499CB902' -d
'INPUT_DATA={"operation":{"Details":{"RESOURCENAME":"Windows
Server","ACCOUNTNAME":"Administrator","RESOURCETYPE":"Windows","PASSWORD"
:"Test123#@!","NOTES":"Testing
API","RESOURCEURL":"http://windowsserver/adminconsole","RESOURCECUSTOMFIEL
D":[{"CUSTOMLABEL":"Secure Resource","CUSTOMVALUE":"YES"}]}}}'
所以两个json对象之间的唯一区别是,文档中的一个在其顶部有'INPUT_DATA={"
的子句,以确定如何使我的json对象能够为此字符串添加前缀?< / p>
答案 0 :(得分:0)
所以,如果我的评论不清楚,那就改为:
{
"operation":{
"Detail":{
"RESOURCENAME":"test123",
"ACCOUNTNAME":"admin",
"RESOURCETYPE":"windows",
"PASSWORD":"Test2Test2",
"NOTES":"From TMS",
"RESOURCEURL":null,
"RESOURCECUSTOMFIELD":[
{
"CUSTOMLABEL":"Asset Tag",
"CUSTOMVALUE":"C100100"
},
{
"CUSTOMLABEL":"Another Tag",
"CUSTOMVALUE":"C100101"
}
]
}
}
}