B4J Question Unavoidable Spaces In JSON from API Upsetting the JSONParser

cklester

Well-Known Member
Licensed User
I'm getting some JSON from a website, and they apparently don't properly terminate their strings. It's causing this error:

(JSONException) org.json.JSONException: Unterminated object at character 31 of {symbol=CITY, name=Manchester City Fan Token, id=1489, tradingSymbol=CITY}

Looks like the spaces in the string values are causing issues.

{symbol=CITY, name=Manchester City Fan Token, id=1489, tradingSymbol=CITY}

How can I properly parse that string into JSON, since I have no control over what I receive from the API?
 

cklester

Well-Known Member
Licensed User
Doing this until something better comes along:

B4X:
            s = s.SubString2(1,s.Length-1).Trim
            Dim sep() As String = Regex.Split(",",s)
            For Each str As String In sep
                Dim seps() As String = Regex.Split("=",str)
                newmap.Put(seps(0).trim,seps(1).Trim)
            Next
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I would contact the Api Author and ask him to fix the defective json-output.
 
Upvote 0
Top