1

私はこのjson配列応答を持っています:

    [
  {
    "status": "active",
    "url": "https:\/\/ikiosk.podio.com\/dev\/apps\/myusers",
    "url_label": "myusers",
    "space_id": 550628,
    "link_add": "https:\/\/ikiosk.podio.com\/dev\/apps\/2304568\/items\/new",
    "app_id": 2304568,
    "date_field": false,
    "link": "https:\/\/ikiosk.podio.com\/dev\/apps\/myusers",
    "config": {
      "allow_edit": true,
      "description": "",
      "item_name": "myusers",
      "type": "standard",
      "icon_id": 251,
      "allow_create": true,
      "usage": "",
      "icon": "251.png",
      "external_id": null,
      "name": "myusers"
    },
    "url_add": "https:\/\/ikiosk.podio.com\/dev\/apps\/2304568\/items\/new"
  },
  {
    "status": "active",
    "url": "https:\/\/ikiosk.podio.com\/dev\/apps\/requests",
    "url_label": "requests",
    "space_id": 550628,
    "link_add": "https:\/\/ikiosk.podio.com\/dev\/apps\/2299738\/items\/new",
    "app_id": 2299738,
    "date_field": true,
    "link": "https:\/\/ikiosk.podio.com\/dev\/apps\/requests",
    "config": {
      "allow_edit": true,
      "description": "",
      "item_name": "request",
      "type": "standard",
      "icon_id": 251,
      "allow_create": true,
      "usage": "",
      "icon": "251.png",
      "external_id": null,
      "name": "Requests"
    },
    "url_add": "https:\/\/ikiosk.podio.com\/dev\/apps\/2299738\/items\/new"
  }
]

そしてここにクラス:

Public Class GetAllApps
    Public pApplication As PodioApplication
End Class


Public Class PodioApplication
    Public status As String
End Class

ここに私のコード:

Dim client As New RestClient()
client.BaseUrl = "https://api.podio.com/"

Dim request As New RestRequest()
request.RequestFormat = DataFormat.Json
request = New RestRequest()
request.Method = Method.[GET]
request.RequestFormat = DataFormat.Json
request.AddParameter("oauth_token", access_token)
request.Resource = "/app/v2//"

Dim resp = client.Execute(Of List(Of GetAllApps))(request)  
RichTextBox1.Text = resp.Content

Dim pApps As List(Of PodioApplication) = resp.Data.[Select](Function(c) c.pApplication).ToList()
MsgBox(pApps.Count)

For Each p As PodioApplication In pApps
   MsgBox(p.status)
Next

以前に書いたjson配列は、resp.Contentの結果です。コード行MsgBox(pApps.Count)で、正しい番号を取得します(このシナリオでは2です)。しかし、for eachループでは、「オブジェクト参照がオブジェクトのインスタンスに設定されていません」という例外エラーが発生します。

私の実装に何か問題がありますか、何かが欠けていますか?

4

1 に答える 1

1

ついに、

私はそれを簡単にしました:

Dim client As New RestClient()
        client.BaseUrl = "https://api.podio.com/"
        Dim request As New RestRequest()
        request.RequestFormat = DataFormat.Json
        request = New RestRequest()
        request.Method = Method.[GET]
        request.RequestFormat = DataFormat.Json
        request.AddParameter("oauth_token", access_token)
        request.Resource = "/app/v2//"
        Dim response = client.Execute(request)
        Dim ser As New JavaScriptSerializer()
        Dim pApps As List(Of PodioApplication) = ser.Deserialize(Of List(Of PodioApplication))(response.Content)

これで、pAppは応答からの正しいデータを取得します。

于 2012-10-15T01:04:58.080 に答える