0
我是JSON的新手,我用文件做了第一次尝试,它工作正常。但是我的第二个文件让我头疼。 的问题是,第二个文件开始与此:[ 我的第一个文件是这样vb.net Json将值转换为类型
{
"GC": {
"Parameters": {
"feed": "gc",
"lang_code": "fr",
"fmt": "json",
} .................
我尝试了很多不同的事情,我一直有一个错误。错误是: 附加信息:将值“person”转换为键入'JSonPerson'时出错。路径 '[0]',1号线,9号位置
这里的第二个JSON文件文本(即先从括号 “[”:
["person",
[{
"id": "19023",
"player_id": "16493",
"coach_id": "0",
"manager_id": "",
"official_id": ""
},
{
"id": "19024",
"player_id": "16494",
"coach_id": "1",
"manager_id": "",
"official_id": ""
}]]
现在我的等级:
Public Class JSonPerson
Public person As List(Of JSon_PersonDetail)
End Class
Public Class JSon_PersonDetail
Public id As String
Public player_id As String
Public coach_id As String
Public manager_id As String
Public official_id As String
Public user_id As String
Public first_name As String
Public last_name As String
End Class
而且我的代码(即第一个文件一样,可以完美运行,但与第二个文件):
Dim client As New WebClient()
Dim stream As Stream = client.OpenRead("c:\Global_files\person.json")
Dim reader2 As New StreamReader(stream)
Dim jsonData As String = reader2.ReadToEnd
Dim obj As List(Of JSonPerson)
obj = JsonConvert.DeserializeObject(Of List(Of JSonPerson))(jsonData)
我试试这个太:
Dim obj As JSonPerson
obj = JsonConvert.DeserializeObject(Of JSonPerson)(jsonData)
但我不能把我的类中的数据我有错误:
是否有人知道什么是我的问题吗?
更新
我也尝试使用JsonTextReader
直接从流中读取,像这样:
Dim client As New WebClient()
Dim stream As Stream = client.OpenRead("c:Global_files\person.json")
Dim reader2 As New StreamReader(stream)
Dim jsonData As String = reader2.ReadToEnd
Dim reader As New JsonTextReader(reader2)
Dim people As JSonPeople
people = JsonSerializer.CreateDefault().Deserialize(Of JSonPeople)(reader)
reader2有数据。变量“reader”为空后。所以人们是空的。