cklester Well-Known Member Licensed User Nov 24, 2021 #1 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} Click to expand... Looks like the spaces in the string values are causing issues. {symbol=CITY, name=Manchester City Fan Token, id=1489, tradingSymbol=CITY} Click to expand... How can I properly parse that string into JSON, since I have no control over what I receive from the API?
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} Click to expand... Looks like the spaces in the string values are causing issues. {symbol=CITY, name=Manchester City Fan Token, id=1489, tradingSymbol=CITY} Click to expand... 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 Nov 24, 2021 #2 Doing this until something better comes along: Code: Copy 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
Doing this until something better comes along: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Nov 24, 2021 #3 cklester said: How can I properly parse that string into JSON Click to expand... You can't because it is not a valid json string. You can test it here: https://jsonlint.com/ cklester said: since I have no control over what I receive from the API? Click to expand... If the API doesn't send properly formatted json then there is no proper way to parse it. You will need to use a "hack" as you did. Upvote 0
cklester said: How can I properly parse that string into JSON Click to expand... You can't because it is not a valid json string. You can test it here: https://jsonlint.com/ cklester said: since I have no control over what I receive from the API? Click to expand... If the API doesn't send properly formatted json then there is no proper way to parse it. You will need to use a "hack" as you did.
DonManfred Expert Licensed User Longtime User Nov 24, 2021 #4 I would contact the Api Author and ask him to fix the defective json-output. Upvote 0
cklester Well-Known Member Licensed User Nov 24, 2021 #5 Erel said: You can't because it is not a valid json string. You can test it here: https://jsonlint.com/ If the API doesn't send properly formatted json then there is no proper way to parse it. You will need to use a "hack" as you did. Click to expand... DonManfred said: I would contact the Api Author and ask him to fix the defective json-output. Click to expand... Yes... Done! Let's see what they say! ? Upvote 0
Erel said: You can't because it is not a valid json string. You can test it here: https://jsonlint.com/ If the API doesn't send properly formatted json then there is no proper way to parse it. You will need to use a "hack" as you did. Click to expand... DonManfred said: I would contact the Api Author and ask him to fix the defective json-output. Click to expand... Yes... Done! Let's see what they say! ?