Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I there.
When someone pass the bellow string to json_server_parse_json() method
{"uid":"9","title":"a","type":"sharing","field_ragot_position":[{"geo":{"lat":"0","lon":"0"}}],"body":"Details goes here"}
it return the following result:
Array
(
["uid"] => 9
["title"] => a
["type"] => sharing
["field_ragot_position"] => Array
(
[0] =>
)
["lon"] => 0"}}
["body"] => Details goes her
)
while it should have returned
array (
'uid' => '9',
'title' => 'a',
'type' => 'sharing',
'field_ragot_position' =>
array (
0 =>
array (
'geo' =>
array (
'lat' => '0',
'lon' => '0',
),
),
),
'body' => 'Details goes here',
)
Comments
Comment #1
hunt3r CreditAttribution: hunt3r commentedI'm experiencing a very similar issue,
When I post this as my node field on node.save:
print_r($_POST) returns this:
Array
(
[hash] => dbfdec8165c72e37e44110c56e7e53a7ed1de054c56c4e62b99ee43697980115
[domain_name] => localhost
[domain_time_stamp] => 12798131653
[nonce] => -1659083932
[method] => node.save
[api_key] => cdfc765c7a59b0a320e8a9aed2282139
[sessid] => MySessionID
[node] => {"uid":3,"body":"Sample body text","title":"Sample Title w/cck","field_condition_rating":[{"0":{"value":"Poor"}}],"type":"trail_condition_update","status":1,"created":1279813165}
)
It always fails on the CCK field saying "field_condition_rating" is required. I've tried a many combinations on serializing this, and haven't had any luck getting the CCK field to post.
Comment #2
dmitrig01 CreditAttribution: dmitrig01 commentedSo what's really needed here is more of a regex parser: for the example [[foo, bar], baz], JSON server will take the [] off and split by , so it'll get
[foo
,bar]
,baz
. Then, it will iterate through: it will see the first [ in [foo, so it will take off the first and last charcters (now fo) and then split by commas (array('fo')) and pass those through (still array('fo')). for bar} and baz, they will get passed through as normal:Input:
[["foo", "bar"], "baz"]
Expected output:
array(array('foo', 'bar'), 'baz')
Actual output:
array(array('fo'), 'bar', 'baz')
Solution:
Instead of parsing as it currently happens, what's needed is some sort of preg parser like in http://api.drupal.org/api/function/drupal_parse_info_file/6
Comment #3
adamdicarlo CreditAttribution: adamdicarlo commentedMaybe the module should require PHP 5.2+ and just use json_decode() -- http://us.php.net/manual/en/function.json-decode.php -- at least until someone writes the crazy regexes necessary to "parse" json and they're found to be reliable. I was going to suggest porting the PHP C implementation... then I looked at it. (Actual pushdown automata implementation.)
Comment #4
kvick CreditAttribution: kvick commentedI'm experiencing the same, can't get cck-fields to work.