A better way to code this.

edwardkchedwardkch MYMember ✭✭

Hi Guys,

I am currently passing json to a REST Call in the method below:

using (var streamWriter = new StreamWriter(request.GetRequestStream()))
{
string json = "{\r\n\"formInputs\":[\r\n{\r\n\"value\": \"782\",\r\n\"id\": \"1\"\r\n},\r\n{\r\n\"value\": \"OP\",\r\n\"id\": \"2\"\r\n},\r\n{\r\n\"value\": \"00001\",\r\n\"id\": \"3\"\r\n},\r\n{\r\n\"value\": \"4343\",\r\n\"id\": \"30\"\r\n}\r\n],\r\n\"formActions\": [\r\n{\r\n\"gridAction\":\r\n{\r\n\"gridID\": \"1\",\r\n\"gridRowUpdateEvents\": [\r\n{\r\n\"rowNumber\": 0,\r\n\"gridColumnEvents\":[\r\n{\r\n\"value\": \"1\",\r\n\"command\": \"SetGridCellValue\",\r\n\"columnID\": \"382\"\r\n},\r\n{\r\n\"value\": \"1\",\r\n\"command\": \"SetGridCellValue\",\r\n\"columnID\": \"116\"\r\n},\r\n{\r\n\"value\": \"1\",\r\n\"command\": \"SetGridCellValue\",\r\n\"columnID\": \"512\"\r\n},\r\n{\r\n\"value\": \"44.00\",\r\n\"command\": \"SetGridCellValue\",\r\n\"columnID\": \"117\"\r\n}\r\n]\r\n}\r\n]\r\n}\r\n},\r\n{\r\n\"command\": \"DoAction\",\r\n\"controlID\": \"4\"\r\n},\r\n{\r\n\"command\": \"DoAction\",\r\n\"controlID\": \"4\"\r\n}\r\n],\r\n\"formServiceAction\": \"U\",\r\n\"formName\": \"P4312_W4312A\"\r\n}";
streamWriter.Write(json);
}

Would like to know how should i do it if i would to pass json with the following scenario below

formInput "value" equals to a variable value from a text box.

Thanks.

Best Regards,
Edward

Answers

  • N_BauaN_Baua INMember ✭✭✭✭✭
    edited August 2017

    @edwardkch ,

    Sorry I might have overlooked that, You might have to create a model class for that.

    string json = @"{  
      'Name': 'Blah Name',  
      'Age': '30',
      'Gender': 'Male'
     }";  
    
    MyOwnType bsObj = JsonConvert.DeserializeObject<MyOwnType>(json);  
    

    N Baua

  • edwardkchedwardkch MYMember ✭✭

    Hi N Baua,

    I am trying to serialise the json object not deserialise.

    Thanks.

Sign In or Register to comment.