JSONitem headache

I’m having a nightmare with JSONitem…

According to the documentation, this should work

[code] dim j as new JSONItem

j.value(“Command”)=“2”
j.value(“email”)=TextField1.text.Trim
j.value(“Username”)=TextField2.text.trim
j.value(“Date”)=d
j.value(“Code”)=a

dim s as string=j.ToString
commsocket.write(s)
Commsocket.flush[/code]

this cause it the app to stop and have a problem with dim s as string=j.ToString
s="", I then looked at the J variable and that made no sense…

Then I tried

[code]dim js as Dictionary
js=new Dictionary

js.value(“Command”)=“2”
js.value(“email”)=TextField1.text.Trim
js.value(“Username”)=TextField2.text.trim
js.value(“Date”)=d
js.value(“Code”)=a

j = new JSONItem
j=js

dim s as string=j.ToString
commsocket.write(s)
Commsocket.flush[/code]

I could see the JS dictionary - that looked all good…

Crashed again on the dim s as string=j.tostring

What am I doing wrong? … I’m using 2014r1 for windows - don’t tell me I need the latest version i have it and It took forever converting the Mac version to work for 64 bit.

Maybe it doesn’t like some of your data, perhaps the date field?
rem the date value and see if that helps.
could always rem all js.values except 1 and see if it’s a data issue?

It was the date value… how would I be able to be able to send a date value as a string and have the helper app convert it into a date from the JSON string?

I guess I could make some more Json strings i.e.

d.Year = 1954
d.Month = 2
d.Day = 10

date.SQLDateTime

https://documentation.xojo.com/api/deprecated/date.html.SQLDateTime

The JSON format only supports NULL, Strings, Number and Boolean data types as well as Arrays of these types and other JSON objects. All other data types must be encoded into one of these types or structures.

Just FYI, what you got was an Exception. The message property probably told you what the problem was.