if I create a webservice that returns a json item whose fields that cointains spaces,
the json content will be result malformed (iin a random position but always near to a space character ) to the parser that interprets it
you can try with this code in handleurl of webapp session
if Request.Path=“test” then
dim dic as Dictionary
dim jout as new JSONItem
dim dataOggi as datetime =DateTime.Now
dim i as Integer
jout.Compact=false
for i= 0 to 100
dic=new Dictionary
dic.Value(“label1”)=“OK”
dic.Value(“label2”)=“pre space1 space2 space3 space4 " + str(i)+” post space5 "
dic.Value(“date”)= dataOggi
jout.Add(dic)
next i
dim dic as Dictionary
dim jout as new JSONItem
dim dataOggi as datetime =DateTime.Now
dim i as Integer
jout.Compact=false
for i= 0 to 100
dim j as new JSONItem
'dic=new Dictionary
j.Value(“label1”)=“OK”
j.Value(“label2”)=“pre space1 space2 space3 space4 " + str(i)+” post space5 "
j.Value(“date”)= dataOggi
jout.Add(j)
next i
When code is pasted in this forum that is not formatted as code, is changed (for example the regular quotes are changed to curly ones). Also is hard to read most of the time.
Can you add ``` one row before/after your code to format it? or select all your code and use the icon:
If you can share a sample project it will be easier for someone to help.
Did you create the parser too? or what are you using to parse/interpret the json?
Using your code above (changing curly quotes) and pasting it to jsonlint.com it says that the JSON is valid.
Edit: this is the code used
If Request.Path="test" Then
Dim dic As Dictionary
Dim jout As New JSONItem
Dim dataOggi As datetime =DateTime.Now
Dim i As Integer
jout.Compact=False
For i= 0 To 100
Dim j As New JSONItem
'dic=new Dictionary
j.Value("label1")="OK"
j.Value("label2")="pre space1 space2 space3 space4 " + Str(i)+" post space5 "
j.Value("date")= dataOggi
jout.Add(j)
Next i
response.Write(jout.ToString)
response.Status=200
Return True
End If
To share a project you need to share as binary (with all external elements) or if you want to share a xojo_project format, you need to zip everything. In other words, your download is not valid.
What options do you select on the https://jsoneditoronline.org/ to see if I can get the same errors?
I don’t see any errors from my output:
It looks like Reqbin changes some hex 20 to hex 0A (I don’t know why).
What I did is:
access Reqbin
install Chrome extension to test locally
copy the result
paste to json editor online
click ‘show me’
check where the error is
paste the text in a Xojo TextArea
put a break point and check as Binary
see how ‘space4 3 po’ has both hex 20 for the space and ‘space4 4 pos’ has hex 0A for one and 20 for the other?
I don’t think this is Xojo’s fault as I can copy the browser result directly and have no errors. I don’t have the time right now to build a test Web application and query it directly with Json Editor Online with the option ‘Open from url’ :
you’re right,
it’s the copy/ paste from reqbin that introduces the problem, I tried with various json parsers and the load from url and everything seems ok,