Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert JSON to string C#

I have webservice hosted on Azure which is returning a JSON object. The JSON response looks like this:

HERE is my JSON RESPONSE

{
   "Results":{
      "output1":{
         "type":"table",
         "value":{
            "ColumnNames":[
               "Accommadation",
               "Sex",
               "Age",
               "SiblingsAndSpouse",
               "ParentChild",
               "Fare",
               "Embarked",
               "Scored Labels",
               "Scored Probabilities"
            ],
            "ColumnTypes":[
               "Int32",
               "String",
               "Nullable`1",
               "Int32",
               "Int32",
               "Double",
               "String",
               "Int32",
               "Double"
            ],
            "Values":[
               [
                  "2",
                  "male",
                  "35",
                  "0",
                  "0",
                  "20",
                  "C",
                  "0",
                  "0"
               ],
               [
                  "2",
                  "male",
                  "35",
                  "0",
                  "0",
                  "20",
                  "C",
                  "0",
                  "0"
               ]
            ]
         }
      }
   }
}

Kindly tell me that how to convert this response to string in C#. I am new to this please help me out,help from you guys will be highly appreciated. Thanks!!

like image 786
Farrukh Ahmed Avatar asked Sep 02 '26 12:09

Farrukh Ahmed


1 Answers

I'm guessing what your really asking is how do to deserialize the JSON. Use Newtonsoft's JSON library's DeserializeObject method and assign it to a dynamic object type.

dynamic dynamicObject= JsonConvert.DeserializeObject(json);

then you can reference each property individually.

string type = dynamicObject.Results.output1.type;
like image 180
josh Avatar answered Sep 04 '26 03:09

josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!