Title: Need help starting with MtGox API Post by: SgtSpike on February 12, 2012, 08:57:09 AM Alright, so I am trying to utilize the MtGox API. JSON still confounds me, so that's what I am having trouble with.
If I use the first block of code posted on the wiki page, I end up with this as output: Code: array(8) { ["Login"]=> string(8) "MYLOGIN" ["Index"]=> string(4) "6532" ["Rights"]=> array(2) { [0]=> string(8) "get_info" [1]=> string(5) "trade" } ["Language"]=> string(5) "en_US" ["Created"]=> string(19) "2011-04-29 21:51:06" ["Last_Login"]=> string(19) "2012-02-12 06:23:55" ["Wallets"]=> array(2) { ["BTC"]=> array(5) { ["Balance"]=> array(4) { ["value"]=> string(10) "0.98988000" ["value_int"]=> string(8) "98988000" ["display"]=> string(15) "0.98988000Â BTC" ["currency"]=> string(3) "BTC" } ["Operations"]=> int(137) ["Daily_Withdraw_Limit"]=> array(4) { ["value"]=> string(12) "400.00000000" ["value_int"]=> string(11) "40000000000" ["display"]=> string(17) "400.00000000Â BTC" ["currency"]=> string(3) "BTC" } ["Monthly_Withdraw_Limit"]=> NULL ["Max_Withdraw"]=> array(4) { ["value"]=> string(12) "400.00000000" ["value_int"]=> string(11) "40000000000" ["display"]=> string(17) "400.00000000Â BTC" ["currency"]=> string(3) "BTC" } } ["USD"]=> array(5) { ["Balance"]=> array(4) { ["value"]=> string(7) "0.06833" ["value_int"]=> string(4) "6833" ["display"]=> string(8) "$0.06833" ["currency"]=> string(3) "USD" } ["Operations"]=> int(167) ["Daily_Withdraw_Limit"]=> array(4) { ["value"]=> string(10) "1000.00000" ["value_int"]=> string(9) "100000000" ["display"]=> string(12) "$1,000.00000" ["currency"]=> string(3) "USD" } ["Monthly_Withdraw_Limit"]=> array(4) { ["value"]=> string(11) "10000.00000" ["value_int"]=> string(10) "1000000000" ["display"]=> string(13) "$10,000.00000" ["currency"]=> string(3) "USD" } ["Max_Withdraw"]=> array(4) { ["value"]=> string(10) "1000.00000" ["value_int"]=> string(9) "100000000" ["display"]=> string(12) "$1,000.00000" ["currency"]=> string(3) "USD" } } } ["Trade_Fee"]=> float(0.55) } array(2) { ["usds"]=> string(7) "0.06833" ["btcs"]=> string(7) "0.98988" } But as I understand the json_decode method, it should look something formatted more like this: Code: array(5) { So, two questions. 1) Why isn't the output pretty/readable? 2) If I wanted to grab a specific variable from that JSON output, what would the syntax look like? Say, if I wanted to store my current BTC balance in a variable, what would the code look like? Title: Re: Need help starting with MtGox API Post by: SgtSpike on February 12, 2012, 09:37:24 PM Bump?
Title: Re: Need help starting with MtGox API Post by: theymos on February 13, 2012, 01:13:07 AM Bitcoin indents its JSON output to make it more readable, but this isn't required. PHP's json_encode doesn't indent. Extra whitespace in JSON is ignored.
Code: array(5) { This is var_dump output, not JSON. Title: Re: Need help starting with MtGox API Post by: SgtSpike on February 13, 2012, 03:01:46 AM Thanks for the reply.
The code I am using also uses var_dump, so I am wondering why it doesn't output in the same manner. Code: <?php Ultimately, it doesn't matter what the var_dump looks like, I was just curious why it didn't show up as it does in all the examples I see. Biggest issue is how do I access the data? If I want to grab the wallet balance from that JSON dump, how would I go about doing so? Once I know the syntax to working with the JSON data, I should be golden. Title: Re: Need help starting with MtGox API Post by: theymos on February 13, 2012, 04:56:31 AM After it's decoded it's just a normal PHP variable. In this case it looks like you'd get the balance using $dec["Wallets"]["BTC"]["Balance"]["value"]. (This is a multi-layer array. Each [] goes down a layer.)
Title: Re: Need help starting with MtGox API Post by: SgtSpike on February 13, 2012, 05:20:23 AM After it's decoded it's just a normal PHP variable. In this case it looks like you'd get the balance using $dec["Wallets"]["BTC"]["Balance"]["value"]. (This is a multi-layer array. Each [] goes down a layer.) Easy enough. Guess I just couldn't understand the array structure with the lack of spacing/indentation. Thank you much!EDIT: Just realized that it is properly spaced/indented in the HTML source when viewing the page, so that helps a ton. Just posting that in case it helps someone else. |