H Hamied Abou Hulaikah Well-Known Member Licensed User Longtime User Feb 11, 2021 #1 JsonTree is great tool & save us a lot of time. in this example, parsing is not complete! B4X: Copy [ {car:"Toyota",model:"Prado"}, {year:2020,price:20000}, {year:2019,price:17000}, {year:2015,price:12000} ] We got this: B4X: Copy Dim parser As JSONParser parser.Initialize(<text>) Dim root As List = parser.NextArray For Each colroot As Map In root Dim car As String = colroot.Get("car") Dim model As String = colroot.Get("model") Next where is the remaining of Json input parsing? "year,price"
JsonTree is great tool & save us a lot of time. in this example, parsing is not complete! B4X: Copy [ {car:"Toyota",model:"Prado"}, {year:2020,price:20000}, {year:2019,price:17000}, {year:2015,price:12000} ] We got this: B4X: Copy Dim parser As JSONParser parser.Initialize(<text>) Dim root As List = parser.NextArray For Each colroot As Map In root Dim car As String = colroot.Get("car") Dim model As String = colroot.Get("model") Next where is the remaining of Json input parsing? "year,price"
Erel B4X founder Staff member Licensed User Longtime User Feb 11, 2021 #2 While it is a valid json, it is designed badly. Arrays are expected to hold items of the same type. Better design: Code: Copy { car:"Toyota", model:"Prado", prices: [ {year:2020,price:20000}, {year:2019,price:17000}, {year:2015,price:12000} ] } JsonTree cannot treat different items in an array differently. Parsing this json string requires all kinds of assumptions that might not be true. Upvote 0
While it is a valid json, it is designed badly. Arrays are expected to hold items of the same type. Better design: Code: Copy { car:"Toyota", model:"Prado", prices: [ {year:2020,price:20000}, {year:2019,price:17000}, {year:2015,price:12000} ] } JsonTree cannot treat different items in an array differently. Parsing this json string requires all kinds of assumptions that might not be true.