iOS Question JSONParser issue

alex2103

Member
Licensed User
Longtime User
In the b4a and b4j application, I use JSONParser to parse invalid JSON strings.
For example,
“[cur-version, 27]”
These lines I get through the network through AsyncStreams.

In b4a and b4j it works fine
B4X:
Private parser As JSONParser
parser.Initialize (text)
Private root As List
root = parser.NextArray
and I get a list with elements

In b4i, I get the Error parsing string because the strings are not in quotes.
error: Error Domain = NSCocoaErrorDomain Code = 3840 "Invalid value around character 1." UserInfo = {NSDebugDescription = Invalid value around character 1.}

Unfortunately, I do not have access to the server side code...
 

alex2103

Member
Licensed User
Longtime User
other strings are not so simple. "[cur-version, 27]" is only for simple examle.
Main part of the protocol is the list-of-lists in JSON format. More messages longer than 4000 Log limit...
In fact, this is like the s-exp format of the LISP language, which is almost similar to json.

Examle from b4a:
B4X:
Log($"sexp=${text}"$)
text = toJSON(text)
Log($"JSON=${text}"$)
Dim parser As JSONParser
parser.Initialize(text)
Dim root As List = parser.NextArray
Log($"ProcessCommand=${root}"$)

In Logs the string is very similar to the string representation of the object, but I don’t know how to make an List object from this string.
In b4a very large lines of this format are handled well with JsonParser.

PS: sorry for my English and google translate
 
Upvote 0

alex2103

Member
Licensed User
Longtime User

I think I will go along the first path and will modify the json string to the correct format.
For b4a, the application has long been completely ready and I would like to use one code in b4i b4a and b4j.
Maybe you can change the iJSON library (version 1.00) so that it works like b4a JSON (version 1.10)?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…