iOS Question JSONParser issue

Discussion in 'iOS Questions' started by alex2103, Apr 16, 2019.

  1. alex2103

    alex2103 Member Licensed User

    In the b4a and b4j application, I use JSONParser to parse invalid JSON strings.
    For example,
    These lines I get through the network through AsyncStreams.

    In b4a and b4j it works fine
    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.
    Unfortunately, I do not have access to the server side code...
  2. Erel

    Erel Administrator Staff Member Licensed User

    If the json strings that you receive are simple as this one then parse it without JsonParser:
    For Each p As String In Regex.Split("[\[,\]]", text)
       p = p.Trim
    If p.Length > 0 Then
    End If
  3. alex2103

    alex2103 Member Licensed 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:
    text = toJSON(text)
    Dim parser As JSONParser
    Dim root As List = parser.NextArray
    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 :)
  4. Erel

    Erel Administrator Staff Member Licensed User

    You have two options:
    1. Modify the json string to make it valid.
    2. Parse it yourself.

    Only you can know which option is simpler. If for example the strings all look like gps-data2 then a simple replace of this term will make it a valid json string.
  5. alex2103

    alex2103 Member Licensed 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)?
  6. Erel

    Erel Administrator Staff Member Licensed User

    iJson library uses the native json SDK. It is not possible to modify it to parse invalid strings.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice