Hi all, I'm having a json file in a domain and I need to take it's data and print in another domain. How to do it? json data can be find here http://beta.qlessticket.com/media.json Please help me.
Hi Shino. You can use the json_decode php's native function. Then do a var_dump to see what kind of data you have: $content = file_get_contents("http://beta.qlessticket.com/media.json"); $json = json_decode($content); var_dump($json); Code (markup): Hope it helps!
I work with json data all the time and decoding and dumping it is always the first step. I never edit the json directly. I put it into a php variable, make the changes and encode again.
Thanks a lot Fisasti I used exactly this function , First the error "Cross-Origin Request Blocked" occurred. Then i contacted server people. They fixed the issue Is there any other solution for this cross-orgin issue?
Good to hear it worked! Look, if you can see the file content from a web-browser, it means the host is accepting external requests, to there is no reason for the Cross-Origin issue. Are you doing this from inside an iframe or loading this content like in a background situation?
Are you sure that code work? I think it should be something like this: $a = file_get_contents('http://beta.qlessticket.com/media.json'); $b = json_decode($a, true); $c = $b['results'][0]['content']; echo $c; Code (markup): I don't need var_dump to see what it is. The data is quite clear though.
Technically, that can be condensed quite a bit: echo json_decode(file_get_contents('http://beta.qlessticket.com/media.json'),true)['results'][0]['content']; PHP:
$content = file_get_contents('http://beta.qlessticket.com/media.json'); $jsonarray = json_decode($content,true); print_r($jsonarray); This is how I coded. It is working fine
What are you going to do with the array? That is not the way to access the array. Are you just going to print out raw data on your site?
I am using JSON in my website like thism you can try it, $url = 'MY JSON URL'; $json = file_get_contents($url); $json = str_replace("\xEF\xBB\xBF",'',$json); $data = json_decode($json); foreach($data as $mydata) { echo $mydata->name ; echo '<br/>'; echo $mydata->views; } PHP: