简体   繁体   中英

How i can add a root name for my json serialized object

I am working on an asp.net mvc-5 web application , and I am using json.net to serliaze a json object and post it back to an external API.

now currently the json object will be as follow:-

{
  "operation":{
    "Detail":{
      "RESOURCENAME":"test123",
      "ACCOUNTNAME":"admin",
      "RESOURCETYPE":"windows",
      "PASSWORD":"Test2Test2",
      "NOTES":"From TMS",
      "RESOURCEURL":null,
      "RESOURCECUSTOMFIELD":{
        "CUSTOMLABEL":"Asset Tag",
        "CUSTOMVALUE":"C100100"
      }
    }
  }
}

but I will get an error from the API that the json is not in the correct format. now based on the API documentation the passed json need to be in the following format :-

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"}]}}}' 

so the only differences between the two json objects , is that the one inside the documentation have the following string at the top of it 'INPUT_DATA={" son to sure how I can mosifty my json object to prefix this string ?

So if my comment wasn't clear, something like this instead:

{
      "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"
            }
          ]
        }
      }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM