2017-12-11 7 views
0

jsonレスポンスに多数のレコードがあるクリオピアAPIを介して取得されたこのjsonからLabel、AskPriceおよびLastPriceを返すにはどうすればよいですか。私はそれらをループする必要があります。しかし、私はそれを配列で必要としています。 "JsonReaderからJArrayを読み込む際にエラーが発生しました。現在のJsonReader項目は配列ではありません:StartObject。Path ''、1行目、1位。強いためasp.net JSONを解析して配列を返す、アイテムが配列ではありませんか?

'json example {"Success":true,"Message":null,"Data":[{"TradePairId":1261,"Label":"$$$/BTC","AskPrice":0.00000012,"BidPrice":0.00000010,"Low":0.00000010,"High":0.00000012,"Volume":68064.22361439,"LastPrice":0.00000011,"BuyVolume":13524665.12308717,"SellVolume":19130552.28589448,"Change":10.0,"Open":0.00000010,"Close":0.00000011,"BaseVolume":0.00734778,"BuyBaseVolume":0.31169133,"SellBaseVolume":2961236.99999879}],"Error":null} 

     Dim url as string = "https://www.cryptopia.co.nz/api/GetMarkets" 
     Dim theurl As New Uri(url) 
     Using webClient = New System.Net.WebClient() 
      Dim json = webClient.DownloadString(theurl) 
      Dim d As JArray = JArray.Parse(json) 
     End Using 
+0

、それは配列ではない、{}アレイはありません。そしてあなたのJSONの例(私は今、URLに気づいた)はaで終わらない}、つまり無効です。 – TehAbstraCt

+0

jsonの例が更新されました。これは有効です。これは単なる例です。そのURLをヒットすると全体が表示されます。あなたは答えがあるかどうか分からない?私は試してみることができますか? – Rob

+0

ええ、答えとして今すぐ入力します – TehAbstraCt

答えて

2

それはのように実行しビューモデル

Class MarketWrapper 
    Property Success As String 
    Property Message As String 
    Property Data As IEnumerable(Of DataWrapper) 
End Class 

Class DataWrapper 
    Property TradePairId As Int32 
    Property Label As String 
    Property AskPrice As Double 
    Property BidPrice As Double 
    Property Low As Double 
    Property High As Double 
    Property Volume As Double 
    Property LastPrice As Double 
    Property BuyVolume As Double 
    Property SellVolume As Double 
    Property Change As Double 
    Property Open As Double 
    Property Close As Double 
    Property BaseVolume As Double 
    Property BuyBaseVolume As Double 
    Property SellBaseVolume As Double 
End Class 

を作成することをお勧めします入力:それはjオブジェクトだ

Dim url as string = "https://www.cryptopia.co.nz/api/GetMarkets" 
Dim theurl As New Uri(url) 
Using webClient = New System.Net.WebClient() 
    Dim json = webClient.DownloadString(theurl) 
    Dim dataWrapper = JsonConvert.DeserializeObject(Of MarketWrapper)(json) 
End Using 
関連する問題