Home > database >  iterate loop through json array
iterate loop through json array

Time:10-21

I am having a terrible time trying to iterate a JSON array. The code attached is one of the last of several variations of what I have tried. I do not understand why I am struggling but really having issues understanding. I have seen and read several examples but can not find the answer I am looking for.

Can someone please help guide me?

Dim j As JObject = JObject.Parse(jsonString)

For Each item As JProperty In nodelist2(0).Item("Values")
   Debug.Print(item.Value)
Next
{[Values, {[
  [
    {
      "Axis": "1",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Acceleration",
      "FileID": 1326,
      "Unit": 0,
      "Value": 0.0547971
    },
    {
      "Axis": "2",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Acceleration",
      "FileID": 1326,
      "Unit": 0,
      "Value": 0.0253521
    },
    {
      "Axis": "3",
      "Channel": -1,
      "Date": "2022/10/20 12:45:48",
      "DescUnit": "Acceleration",
      "FileID": 1326,
      "Unit": 0,
      "Value": 0.0194674
    }
  ],
  [
    {
      "Axis": "1",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Velocity",
      "FileID": 1326,
      "Unit": 2,
      "Value": 1.07888
    },
    {
      "Axis": "2",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Velocity",
      "FileID": 1326,
      "Unit": 2,
      "Value": 0.275461
    },
    {
      "Axis": "3",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Velocity",
      "FileID": 1326,
      "Unit": 2,
      "Value": 0.196169
    },
  ],
  [
    {
      "Axis": "1",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Acceleration Envelope",
      "FileID": 1326,
      "Unit": 6,
      "Value": 0.0292101
    },
    {
      "Axis": "2",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Acceleration Envelope",
      "FileID": 1326,
      "Unit": 6,
      "Value": 0.0187995
    },
    {
      "Axis": "3",
      "Channel": -1,
      "Date": "2022/10/20 00:09:47",
      "DescUnit": "Acceleration Envelope",
      "FileID": 1326,
      "Unit": 6,
      "Value": 0.0122969
    },
 ]
]}]}

CodePudding user response:

The JSON you provided is wrong, below is a correct version of it. For this, you have a JSON object with element Values that is a JSON array of JSON arrays.

Hope this helps :)

{
   "Values":[
      [
         {
            "Axis":"1",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Acceleration",
            "FileID":1326,
            "Unit":0,
            "Value":0.0547971
         },
         {
            "Axis":"2",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Acceleration",
            "FileID":1326,
            "Unit":0,
            "Value":0.0253521
         },
         {
            "Axis":"3",
            "Channel":-1,
            "Date":"2022/10/20 12:45:48",
            "DescUnit":"Acceleration",
            "FileID":1326,
            "Unit":0,
            "Value":0.0194674
         }
      ],
      [
         {
            "Axis":"1",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Velocity",
            "FileID":1326,
            "Unit":2,
            "Value":1.07888
         },
         {
            "Axis":"2",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Velocity",
            "FileID":1326,
            "Unit":2,
            "Value":0.275461
         },
         {
            "Axis":"3",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Velocity",
            "FileID":1326,
            "Unit":2,
            "Value":0.196169
         }
      ],
      [
         {
            "Axis":"1",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Acceleration Envelope",
            "FileID":1326,
            "Unit":6,
            "Value":0.0292101
         },
         {
            "Axis":"2",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Acceleration Envelope",
            "FileID":1326,
            "Unit":6,
            "Value":0.0187995
         },
         {
            "Axis":"3",
            "Channel":-1,
            "Date":"2022/10/20 00:09:47",
            "DescUnit":"Acceleration Envelope",
            "FileID":1326,
            "Unit":6,
            "Value":0.0122969
         }
      ]
   ]
}
  • Related