2014-10-07 61 views
1

我越来越格式化,因为这如何反序列化JSON结构?

{"UFs": [ 
    { 
    "Valor": "24.184,92", 
    "Fecha": "2014-10-07" 
    } 
    ]} 

我想访问此处显示的值和日期信息。

我有一类

Public Class clValores 
    Private pTipoValores As String 
    Private pValores As String 
    Public Property Fecha() As String 
     Get 
      Return pTipoValores 
     End Get 
     Set(ByVal value As String) 
      pTipoValores = value 
     End Set 
    End Property 
    Public Property Valor() As String 
     Get 
      Return pValores 
     End Get 
     Set(ByVal value As String) 
      pValores = value 
     End Set 
    End Property 
End Class 

而这种代码

Dim webClient As New System.Net.WebClient 
Dim result As String = webClient.DownloadString("http://api.sbif.cl/api-sbifv3/recursos_api/uf?apikey=xxxxxxxxxxxxxxxxxxxxxxx&formato=JSON") 

Dim Valor As clValores = JsonConvert.DeserializeObject(Of clValores)(result) 

Response.Write(Valor.Fecha) 
Response.Write(Valor.Valor) 

但在运行代码时勇猛什么。我缺少

回答

0

从我在这个post阅读,这将是那么容易,因为简单地包装的UF参数一样,所以要克雷娅察含

Public Class UFsContainer 
    public UFs as List(Of clValores) 
End Class 

,然后一个额外的类与反序列化新班,而不是clValores

+0

我试过这样Dim Valor As UFsContainer = JsonConvert.DeserializeObject(Of UFsContainer)(result)但我没有得到任何东西 – Corobori 2014-10-08 00:20:25

+0

对不起,我刚才看到clValores是一个数组,所以它应该是一个List(Of clValores)来正确地反序列化它 – Icepickle 2014-10-08 10:40:04