How can create a json string in vb.net?

时间:2019-05-31 11:56:24

标签: vb.net

This is my code in php:

$posts = array();
for ($row = 2; $row <4; $row++) {
     $post= array();
     $post["series"]= 1;
     $post["modelno"]= 2;       
     $posts[] = array('Item'=>$post);
}   
$json=json_encode(json_encode(array('table1'=>$posts)));

Result:

"{\"table1\":[{\"Item\":{\"series\":1,\"modelno\":2}},{\"Item\":{\"series\":1,\"modelno\":2}}]}"

I want convert this process to vb.net: My code by vb.net:

       Dim jarray As New JArray
        For i = 2 To 3
            Dim ji As New JObject
            ji("series") = 1
            ji("modelno") = 2
            jarray.Add(ji)
        Next
         Dim jData = New JObject
        jData("table1") = jarray
        Dim strJson = jData.ToString

This is result in vb.net:

{
  "table1": [
    {
      "series": 1,
      "modelno": 2
    },
    {
      "series": 1,
      "modelno": 2
    }
  ]
}

I have 2 the problem in vb.net:

  1. How can add name Item to json object.

  2. How encode the same php.

Thank you.

0 个答案:

没有答案