2011-09-08 60 views
2

我試圖解析一些json我從服務中取回。 例如它的返回在vb.net解析json與jrock

 { 
    "error" : 
    { 
    "code" : 500, 
    "message" : "Error Executing Task. Error executing tool.", 
    "details" : [] 
    } 
} 

所有我需要的是在信息欄中的文本。使用jayrock獲取數據的簡單方法是什麼?我有:

Dim request As HttpWebRequest 
    Dim response As HttpWebResponse = Nothing 
    Dim jarray As Jayrock.Json.JsonObject 
request = DirectCast(WebRequest.Create(url), HttpWebRequest) 
     response = DirectCast(request.GetResponse(), HttpWebResponse) 

     Dim reader As JsonTextReader = New JsonTextReader((New StreamReader(response.GetResponseStream))) 


     jarray = Jayrock.Json.Conversion.JsonConvert.Import(reader) 

是什麼讓「信息」的數據

回答

2

我只能爲自己說話的最efficant方式,但我會寫這樣:

Dim cMessage As String = "{ ""error"" : { ""code"" : 500, " & _ 
           """message"" : ""Error Executing Task. " & _ 
           "Error executing tool.""," & _ 
           """details"" : [] " & _ 
           "}" & _ 
           "}" 

Dim objResponse As JsonObject 


objResponse = CType(JsonConvert.Import(cMessage), JsonObject) 

MsgBox("Last response was: " + objResponse("error")("message")) 

PS:別忘了導入Jayrock.Json和Jayrock.Json.Conversion