Question about using JSON_ENCODE()

I'm developing a basic webservice to compliment a mobile application I'm
developing or iPhone. While I know how to encode simple variables and
arrays, I'm not sure how to do what I'm needing to do. Basically, I want to
encode a status message to return to the mobile client. Something like

"status" "good_request"

Right now, I'm thinking I should put this in an array and encode/return
that. But is that the right way of thinking? Is there a more correct or
better way to do this?

Thanks!
Anthony


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
papillion [ Fr, 08 Januar 2010 21:43 ] [ ID #2028205 ]

Re: Question about using JSON_ENCODE()

--00151774041cca739a047cad9583
Content-Type: text/plain; charset=ISO-8859-1

Yup,

you put result in an array
$result = array('status' => 'good');
and return encoded string
return Json_Encode($result);

your client will get a string
'{"status": "good"}'
and you use your client tech(eg. javascrpt) to decode this string and finall
get an object

On Fri, Jan 8, 2010 at 3:43 PM, Anthony Papillion <papillion [at] gmail.com>wrote:

> I'm developing a basic webservice to compliment a mobile application I'm
> developing or iPhone. While I know how to encode simple variables and
> arrays, I'm not sure how to do what I'm needing to do. Basically, I want to
> encode a status message to return to the mobile client. Something like
>
> "status" "good_request"
>
> Right now, I'm thinking I should put this in an array and encode/return
> that. But is that the right way of thinking? Is there a more correct or
> better way to do this?
>
> Thanks!
> Anthony
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--00151774041cca739a047cad9583--
Ryan Sun [ Fr, 08 Januar 2010 22:08 ] [ ID #2028206 ]

Re: Question about using JSON_ENCODE()

Thank you Ruan!
This is just what I was looking for!

Anthony


"Ryan Sun" <ryansun81 [at] gmail.com> wrote in message
news:f7f19ac21001081308r4b202d45vedaf3561536adff0 [at] mail.gmail .com...
> Yup,
>
> you put result in an array
> $result = array('status' => 'good');
> and return encoded string
> return Json_Encode($result);
>
> your client will get a string
> '{"status": "good"}'
> and you use your client tech(eg. javascrpt) to decode this string and
> finall
> get an object
>
> On Fri, Jan 8, 2010 at 3:43 PM, Anthony Papillion
> <papillion [at] gmail.com>wrote:
>
>> I'm developing a basic webservice to compliment a mobile application I'm
>> developing or iPhone. While I know how to encode simple variables and
>> arrays, I'm not sure how to do what I'm needing to do. Basically, I want
>> to
>> encode a status message to return to the mobile client. Something like
>>
>> "status" "good_request"
>>
>> Right now, I'm thinking I should put this in an array and encode/return
>> that. But is that the right way of thinking? Is there a more correct or
>> better way to do this?
>>
>> Thanks!
>> Anthony
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
papillion [ Sa, 09 Januar 2010 08:50 ] [ ID #2028266 ]
PHP » gmane.comp.php.general » Question about using JSON_ENCODE()

Vorheriges Thema: jsonDebug/htmlMicroscope 1.1.0 - auto-includes a full function trace
Nächstes Thema: Clean PHP 5.2.12 Build Core Dumping