I think I may be losing my mind. Perhaps someone can help.
Posting regular strings 'like this' works as expected via JSON server. Posting JSON strings like:
{"Name":"Beatles","Country":"England","YearFormed":1959,"Style":"Rock'n'Roll","Members":["Paul","John","George","Ringo"]}
does not work. Via Firebug it appears that it is sending the string as it should.
On submit, I receive no errors, but the JSON field does not write to the database via JSON server.
Copying it over to the admin/build/services/browse interface and the field accepts the JSON string and writes it to the database.
Please point me in the right direction. I'm off to bed :)
Comments
Comment #1
yajnin CreditAttribution: yajnin commentedAttempt to be clearer:
Passing data from the JS app, back and forth, from the database. No problem.
However -- while sending regular string arguments in the POST object, the intention is to include a JSON string argument as well.
The regular arguments write to corresponding table fields in the DB as normal. ** The JSON argument (containing a lengthy string of fields) would write to (and be called from) a single table field in the DB.
The problem appears to be in parsing of JSON server data object.
It seems to choke when it contains a sub object such as a JSON string.
Comment #2
yajnin CreditAttribution: yajnin commentedAfter encoding the object into a string, it seems mandatory to escape the first curly bracket with another character. Anything other than ' [ ' or ' { ' which confuse the JSON parser.
My current attempt is this:
From there you'd just need to remove the # and you're golden. It works, if not ideal.
Anyone with a wiser solution?
Comment #3
yajnin CreditAttribution: yajnin commentedFor this thread I have a client-side solution / work-around.
Originally posted here: http://groups.drupal.org/node/24372#comment-84315
Comment #4
yajnin CreditAttribution: yajnin commentedThe inability to accept a plain JSON string as an argument, and pass it to Services may be a bug of JSON server. Perhaps the ability to do this is more appropriately labled a feature request. In hope of having this addressed sooner, I'm flagging it as a bug for the maintainer's review.