Is there a recommended way to send an object using json between server and client? Should I use only lowercase for properties, should I use an object or an array?
Update: this question came to me because by default php encodes the associative array as an object (after decoding it)
You must create an array and then use the method . It doesn't matter if uppercase or lowercase letters matter. json_encode
json_encode
$a = array( 'Test' => 42, 'example' => 'Testing' ); echo json_encode($a); // {"Test":42,"example":"Testing"}
When decoding in PHP, pass trueas a second parameter to json_decodeto convert objects to arrays.
true
json_decode
$data = json_decode($json, true);
.
. , - . , , . , , .
, , . , JSON (.. : {'key':'value','key2':'value2'}); , JSON (.. ['value1','value2']). , : JSON, ; .
{'key':'value','key2':'value2'}
['value1','value2']
(PHP, , - PHP, PHP ).
, , . , javascript javascript. - , . JSON , - . , javascript, PHP , . , []. , {}. PHP : [], {}.
[]
{}