JSON variabiles [message #178877] |
Fri, 17 August 2012 14:54 |
Sarah
Messages: 30 Registered: December 2010
Karma: 0
|
Member |
|
|
Hi, I use this code
$data['code'][] = $result;
Header('Content-type: application/json');
echo json_encode($data);
exit;
For return a value using JSON.
{"code":["202"]}
(1 value returned)
Now I would like to return not only 1 value but 2 (2 variables)
How can I return another value? First value $result, second value $second
$data['code'][] = $result; //questa è la prima variabile passata
$data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
Thanks
|
|
|
Re: JSON variabiles [message #178878 is a reply to message #178877] |
Fri, 17 August 2012 16:12 |
simgish
Messages: 3 Registered: August 2012
Karma: 0
|
Junior Member |
|
|
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks
If you're wanting the keys to both be "code", assign the array like this:
$data[]['code'] = '123';
$data[]['code'] = '456';
That will give you:
[Object { code="123"}, Object { code="456"}]
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks
If you're wanting the keys to both be "code", build the array like this:
$data[]['code'] = '123';
$data[]['code'] = '456';
That will give you:
[Object { code="123"}, Object { code="456"}]
|
|
|
Re: JSON variabiles [message #178879 is a reply to message #178877] |
Fri, 17 August 2012 16:27 |
simgish
Messages: 3 Registered: August 2012
Karma: 0
|
Junior Member |
|
|
On Friday, August 17, 2012 10:54:26 AM UTC-4, dand...@gmail.com wrote:
> Hi, I use this code
>
>
>
> $data['code'][] = $result;
>
> Header('Content-type: application/json');
>
> echo json_encode($data);
>
> exit;
>
>
>
> For return a value using JSON.
>
>
>
> {"code":["202"]}
>
>
>
> (1 value returned)
>
>
>
> Now I would like to return not only 1 value but 2 (2 variables)
>
>
>
>
>
>
>
> How can I return another value? First value $result, second value $second
>
>
>
> $data['code'][] = $result; //questa è la prima variabile passata
>
> $data['code'][] = ???? //How can I pass also $second variabile for return 2 values in JSON?
>
>
>
> Thanks
$data['code'][] = '123';
$data['code'][] = '456';
That will give you:
{"code":["123","456"]}
|
|
|