I would recommend reading http://json.org/

If the JSON string you posted is the exact one you are receiving, you will
have the most trouble with the fact that it's invalid JSON. JSON requires
double quotes on strings, so you would expect the following:

{
    "timestamp": "139396594",
    "acct1":
    {
        "available" : "12594.56",
        "pending" : "415.4264"
    },
    "reserve" :
    {
        "available" : "175.11"
    }
}

Here's a snippet of how you would use json_decode():

<?php
$currentBal = json_decode($api->cur_bal());
echo $currentBal->acct1->pending;


On Tue, Sep 2, 2014 at 8:38 AM, Brian J. Rogers <[email protected]>
wrote:

> +1 to John Shaver's answer
>
>
> On Tue, Sep 2, 2014 at 3:57 AM, John Shaver <[email protected]> wrote:
>
> > Of an API returns JSON data, it is basically returning a string.  That
> > string is a just a representation of the dictionary.  If you want to
> access
> > the data, you would use json_decode() to convert the string to a php
> > object:
> >
> > http://php.net/manual/en/function.json-decode.php
> >
> > -John
> >  On Sep 2, 2014 1:32 AM, "Dan Egli" <[email protected]> wrote:
> >
> > > Hey Pluggers, I need some quick reference help in PHP. Apparently I
> can't
> > > think how to compose the right Google query at the moment. I must need
> to
> > > practice my GoogleFoo more. :S
> > >
> > > I have a program that I'm writing in PHP. It needs to reference a 3rd
> > party
> > > API. However, that API wants to return most of the values I'm looking
> as
> > > what I think are JSON dictionaries. This is something I've never dealt
> > with
> > > (or even heard of) before. How in the heck do you access a part of a
> JSON
> > > dictionary? For example, given the following:
> > >
> > > var_dump($api->cur_bal());
> > > {'timestamp': '139396594', 'acct1': { 'available' : '12594.56',
> > 'pending' :
> > > '415.4264' }, 'reserve' : { 'available' : '175.11' }}
> > >
> > > How would I access, for example, the value of 'pending' under 'acct1'?
> Or
> > > the 'available' under reserve?
> > >
> > > Any good web sites (specific URLs needed, please!) that could also
> > explain
> > > what a JSON is and how it gets used would be greatly appreciated.
> > >
> > > Thanks folks!
> > > --- Dan
> > >
> > > /*
> > > PLUG: http://plug.org, #utah on irc.freenode.net
> > > Unsubscribe: http://plug.org/mailman/options/plug
> > > Don't fear the penguin.
> > > */
> > >
> >
> > /*
> > PLUG: http://plug.org, #utah on irc.freenode.net
> > Unsubscribe: http://plug.org/mailman/options/plug
> > Don't fear the penguin.
> > */
> >
>
> /*
> PLUG: http://plug.org, #utah on irc.freenode.net
> Unsubscribe: http://plug.org/mailman/options/plug
> Don't fear the penguin.
> */
>

/*
PLUG: http://plug.org, #utah on irc.freenode.net
Unsubscribe: http://plug.org/mailman/options/plug
Don't fear the penguin.
*/

Reply via email to