vb.net Json Error converting value to type -


i'm newbie in json, made first try file , works fine. second file gives me headache. problem second file start : [ first file this

{ "gc": {     "parameters": {         "feed": "gc",         "lang_code": "fr",         "fmt": "json",     } ................. 

i try many different things , have error. error : additional information: error converting value "person" type 'jsonperson'. path '[0]', line 1, position 9.

here's second json file text (that start bracket "[" :

["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": "" }]] 

now class:

public class jsonperson     public person list(of json_persondetail) end class  public class json_persondetail   public id string   public player_id string   public coach_id string   public manager_id string   public official_id string   public user_id string   public first_name string   public last_name string end class 

and code (that same first file, works perfect, not second file):

dim client new webclient()         dim stream stream =  client.openread("c:\global_files\person.json")         dim reader2 new streamreader(stream)         dim jsondata string = reader2.readtoend         dim obj list(of jsonperson)         obj = jsonconvert.deserializeobject(of list(of jsonperson))(jsondata) 

i try too:

        dim obj jsonperson         obj = jsonconvert.deserializeobject(of jsonperson)(jsondata) 

but i'm not able push data inside class have errors:

does know what's problem ?

update

i tried reading directly stream using jsontextreader, so:

dim client new webclient() dim stream stream = client.openread("c:global_files\person.json") dim reader2 new streamreader(stream) dim jsondata string = reader2.readtoend  dim reader new jsontextreader(reader2) dim people jsonpeople people = jsonserializer.createdefault().deserialize(of jsonpeople)(reader) 

reader2 have data. after variable "reader" empty. people empty.

here's way did it:

        dim client new webclient()         dim stream stream = client.openread("c:\global_files\person.json")         dim reader2 new streamreader(stream)          dim jsondata string = reader2.readtoend          dim jresults jarray = jarray.parse(jsondata) 'here know children #1 need         dim data list(of jtoken) = jresults.item(1).children().tolist          dim vlistofperson new list(of json_persondetail)         each item in data             dim itemarray array = item.toarray             dim person new json_persondetail              each element in itemarray                  select case element.name                     case "id"                         person.id = element.value                     case "player_id"                         person.player_id = element.value                     case "coach_id"                         person.coach_id = element.value                     case "manager_id"                         person.manager_id = element.value                     case "official_id"                         person.official_id = element.value                     case "user_id"                         person.user_id = element.value                     case "first_name"                         person.first_name = element.value                     case "last_name"                         person.last_name = element.value                 end select             next             vlistofperson.add(person)         next 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -