0

How we can pass value to details section in below Josn

JSON File

{
  "firstName": "JB000123",
  "LASTNAme": "SHP0000123",
  "details": [
    {
      "a": "Full Trucking Load",
      "b": "2",
      "c": "USD"
    },
    {
      "a": "Ocean Freight",
      "b": "2",
      "c": "USD"
    }
  ]
}

How to add records in Details part

var client = new RestClient(URL);
client.Authenticator = new HttpBasicAuthenticator(Username, Password);
var request = new RestRequest("/xyz/xyzz/", Method.POST);
request.AddParameter("firstName", "Test"); 
request.AddParameter("LASTNAme", "Tets Last Name"); 
request.AddParameter("details", ???); 

IRestResponse response = client.Execute(request);
var content = response.Content;
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
raj
  • 13
  • 6
  • No, I have assign values in "FirstName" and "Lastname" but not able to pass value in details section, when its successfully validate i will get output in Content variable – raj Jan 09 '19 at 07:53
  • 1
    Unless my understanding is incorrect, you're currently building a `application/x-www-form-urlencoded` body (based on [the docs here](https://github.com/restsharp/RestSharp/wiki/ParameterTypes-for-RestRequest)), meaning that the data will be sent like `firstName=JB000123&LASTNAme=SHP0000123`. I'm not sure how you would pass complex objects in this format since you haven't specified how the server will be handling it. You'll need to work that out first. – ProgrammingLlama Jan 09 '19 at 08:01
  • Maybe [this](https://stackoverflow.com/questions/6312970/restsharp-json-parameter-posting) might help? – ProgrammingLlama Jan 09 '19 at 08:07
  • What does your endpoint expect as param, a 'details' object, or an array of objects? – Mo A Jan 09 '19 at 10:16
  • Thank you, solved. – raj Jan 09 '19 at 11:28

0 Answers0