Send object using json

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)

+5
source share
3 answers

You must create an array and then use the method . It doesn't matter if uppercase or lowercase letters matter. 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.

$data = json_decode($json, true);
+5
source

.

. , - . , , . , , .

, , . , JSON (.. : {'key':'value','key2':'value2'}); , JSON (.. ['value1','value2']). , : JSON, ; .

(PHP, , - PHP, PHP ).

+1

, , . , javascript javascript. - , . JSON , - . , javascript, PHP , . , []. , {}. PHP : [], {}.

0
source

All Articles