JSON Headache

icakinser

Member
Licensed User
Longtime User
Sorry to post here but StackOverflow wont let me log in
I am having a very hard time understanding the JSON documents and get a map error on the example. Can someone help me to parse:

{"content": { "btitle":"Robeerrt" "author":"Bob" "publisher":"Bert" "other":"Nada" "chapters":"2"
"chapter0": {
"title":"jjh"
"content":"3C666F6E7420666163653D275365676F65205549272073697A653D2732273E4661727420666F72206D65206269746368206661727420666F72206D653C2F666F6E743E"

"chapter1": {
"title":"jjh"
"content":"3C666F6E7420666163653D275365676F65205549272073697A653D2732273E41206A6F622069732061206A6F623C2F666F6E743E"

"chapter2": {
"title":"jjh"
"content":"3C666F6E7420666163653D275365676F65205549272073697A653D2732273E426F6220697320626F623C2F666F6E743E"
}
}
}
}}

I checked online tools and they all say its valid JSON but am having the worst time getting the parser to actualy parse the info and put the chapters into a map and the titles into a separate map to be put into a listbox. I am new to this object oriented programming so sorry if this comes off as a noob sort of thing :sign0013:
 

thedesolatesoul

Expert
Licensed User
Longtime User
Looks like its nested into two JSON objects.
B4X:
Dim JSON As JSONParser
Dim Map1 As Map
JSON.Initialize(JSONStringToParse) 'Read the text from a file.
Map1 = JSON.NextObject 
btitle = Map1.Get("btitle")
... so on for the first few objects
Dim JSON2 as JSONParser
Dim Map2 as Map
JSON2.Initialize(Map1.Get("chapter0"))
Map2 = JSON2.NextObject
chaptertitle = Map2.Get("title")
chaptercontent = Map2.Get("content")

This is what I THINK. I havent tried it.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…