How can I parse JSON string from HttpClient?

There are three ways that come to mind.

  1. Assuming the json is consistent and the structure of the response will not change frequently, I would use a tool like json2csharp or jsonutils to create c# classes.

    then call:

    {GeneratedClass} obj = JsonConvert.DeserializeObject<{GeneratedClass}>(result);
    

    This will give you a strongly typed object that you can use.

  2. You can skip the class generation and use a dynamic object:

    dynamic obj = JsonConvert.DeserializeObject<dynamic>(result)
    

    and access properties such as:

    obj.dialog.prompt;
    
  3. You can use a JObject and access its properties using strings

    JObject obj = JsonConvert.DeserializeObject(result);
    
    obj["dialog"]["prompt"]
    

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)