Search code examples
vb.netwebclientrequest-headers

WebClient and VB.NET - Adding headers that have arrays


So I'm looking at something similar to this:

POST https://xxxx.io/testAPI
{
  "test": "string",
  "data": {
    "name": "",
    "description": "string",
  }
}

Adding general headers is fine:

NCLient3.QueryString.Add("test", "Test string")

But for data -> name and data -> description, how would I do it in this regard as it's an array?


Solution

  • Well, First, this is not a valid JSON.

    {
    "test": "string",
    "data": {
    "name": "",
    "description": "string"
     }
    }
    

    You can get their values using Linq.

    Dim json As String = "{'test': 'string','data': {'name': '','description': 'string'}}"
    Dim jsn = Newtonsoft.Json.Linq.JObject.Parse(json)
    Dim finalvalue As String = jsn.GetValue("data").Item("description").ToString()
    

    and you'll get the value => string