1

I am making a website to display the data at https://api.captcoin.com/address/top/100. I need to be able to make the website take variables("address", "percent", "balance", and "rank") from this script and make them local variables in my site so I can display them. How can I take these variables and use them in my site?

2
  • 1
    Look up "JSON parser" and start from there. Any refined, specific questions please feel free to ask again. This question as it stands is susceptible to downvotes. Commented Aug 30, 2014 at 12:09
  • try using jquery and parsing the json data Commented Aug 30, 2014 at 12:11

3 Answers 3

3

First you need to get the remote page contents:

$remote = file_get_contents('link');

Then, since the data is in json format, you need to decode it using json_decode function.

$data = json_decode($remote, true); 

true means that $remote should be decoded as associative array.

And finally you can access the data like an ordinary php array:

echo $data['top'][0]['address'];

Also, you should add some logic to handle situations when remote server is not accessible.

Sign up to request clarification or add additional context in comments.

1 Comment

I get: Catchable fatal error: Object of class stdClass could not be converted to string in (my PHP file) on line 17--line 17 is $data = json_decode($remote, true);
0

Use json_decode to convert the content of that url into an array and then search through it like you would through any array.

To get the actual content of the site please refer to this post Get file content from a URL?

Comments

0

You can either do it with javascript or php.

With javascript use this: http://api.jquery.com/jquery.getjson/ You take the pages output and push them as variables to the php.

With php you can use http://php.net/manual/en/function.json-decode.php

You make an array to push the json data into:

$object = array();
$json = file_get_contents('https://api.captcoin.com/address/top/100');
$object = json_decode ( string $json , true)

Be aware this is untested and read the json_decode api to customize the function-call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.