【发布时间】:2016-10-05 12:16:04
【问题描述】:
我正在尝试反序列化一个 JSON 字符串,然后遍历它的结果。 我从这里开始:http://www.newtonsoft.com/json/help/html/QueryJsonLinq.htm
我想把它翻译成 VB.NET 版本,但是我遇到了各种各样的错误。 我尝试了几个翻译器都没有运气(例如http://converter.telerik.com/)。
JSON 字符串
{
"responseHeader": {
"status": 0,
"QTime": 1,
"params": {
"sort": "title asc"
"rows": "10"
}
},
"response": {
"numFound": 3,
"start": 0,
"docs": [{
"title": "Amsterdam",
"cityurl": "amsterdam"
}, {
"title": "London",
"cityurl": "london"
}, {
"title": "New York",
"cityurl": "new-york"
}]
}
}
首先我尝试反序列化 JSON:
Dim postTitles = From p In rss("channel")("item")DirectCast(p("title"), String)
'End of Statement Expected on `DirectCast(p("title"), String)`
然后我尝试遍历结果,但是我在下面尝试的两种方法都不起作用
For Each item As var In postTitles
Log("title", item)
Next
'type 'var' is not defined
For Each (dim item In postTitles)
Log("title", item)
Next
'Expression expected (on `dim`)
VB.NET 中执行此操作的正确代码是什么?
【问题讨论】:
标签: asp.net json vb.net linq deserialization