使用VB.Net获取JSON数据

时间:2016-05-26 08:36:42

标签: json vb.net

我有一个像这样的JSON字符串:

    {"Data": {
  "Response": {
    "Id": 164,
    "DateTime": "2016-05-25 11:44:55Z"
  },
  "Order": {
    "Reference": "5295d323-c4ab-44be-bba6-6437d76a83b0",
    "DateTime": "2016-05-25 14:44:26Z",
    "CustomReference": null
  },
  "Request": {
    "Id": 246,
    "StatusId": 20,
    "Error": {
      "Code": null,
      "Message": null,
      "ExtraData": null
    }
  },
  "Transactions": [
    {
      "Id": 105,
      "Reference": "NTHpmP0000000105",
      "VPosId": 1,
      "PaySetId": 1,
      "PaySetName": "Varsayılan ödeme seti",
      "Installment": 1,
      "PlusInstallment": 0,
      "PaymentDeferral": 0,
      "CommTypeId": 20,
      "CommRate": "0,0000",
      "IsTest": false,
      "Detail": [
        {
          "Id": 105,
          "Status": 1,
          "Type": 40,
          "DateTime": "2016-05-25 14:44:54Z",
          "Error": {
            "Code": null,
            "Message": null
          },
          "Amount": "300,00",
          "NetAmount": "300,0"
        }
      ],
      "Items": [],
      "CustomData": [
        {
          "IntegrationId": "1",
          "Value": "44"  // i need that one
        }
      ]
    }
  ]
}}

我试图获得" CustomData"使用此代码的值:

 Dim ser As JObject = JObject.Parse(a)
    Dim data As List(Of JToken) = ser.Children().ToList
    Dim output As String = ""


    For Each item As JProperty In data
        item.CreateReader()
' code here
    Next

Visual Studio为我提供了访问" CustomData"值:

(New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(item.ChildrenTokens)).Items(0),Newtonsoft.Json.Linq.JObject).ChildrenTokens)).Items(3),Newtonsoft.Json.Linq.JProperty).ChildrenTokens)).Items(0),Newtonsoft.Json.Linq.JArray).ChildrenTokens)).Items(0),Newtonsoft.Json.Linq.JObject).ChildrenTokens)).Items(13),Newtonsoft.Json.Linq.JProperty).ChildrenTokens)).Items(0),Newtonsoft.Json.Linq.JArray).ChildrenTokens)).Items(0),Newtonsoft.Json.Linq.JObject).ChildrenTokens)).Items(1)

当我尝试使用它时:

            Dim ss = (New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(DirectCast((New System.Collections.Generic.Mscorlib_CollectionDebugView(Of Newtonsoft.Json.Linq.JToken)(item.ChildrenTokens)).Items(0), Newtonsoft.Json.Linq.JObject).ChildrenTokens)).Items(3), Newtonsoft.Json.Linq.JProperty).ChildrenTokens)).Items(0), Newtonsoft.Json.Linq.JArray).ChildrenTokens)).Items(0), Newtonsoft.Json.Linq.JObject).ChildrenTokens)).Items(13), Newtonsoft.Json.Linq.JProperty).ChildrenTokens)).Items(0), Newtonsoft.Json.Linq.JArray).ChildrenTokens)).Items(0), Newtonsoft.Json.Linq.JObject).ChildrenTokens)).Items(1)

它给了我这个错误: ' System.Collections.Generic.Mscorlib_CollectionDebugView(Of T)'在这种情况下无法访问,因为它是“朋友”。 Error Message

访问该数据应该怎么做?

0 个答案:

没有答案