I'm working with the yahoo api - and pretty much going off their example. BUT I'm getting errors such as: Invalid argument supplied for foreach()
Here is the actual foreach statement:
foreach ($data->query->results->result as $r){
// do something with the data
}
The entire code i'm running is here:
$c =curl_init("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20local.search%20where%20state%3D'delaware'%20and%20city%20%3D%20'smyrna'%20and%20query%3D'pizza'&format=json");
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 20); // query times out after 20 seconds
$data = curl_exec($c); // I asked for data format to be in json in the query it appears to be returned decoded
//print_r($data);
$data = curl_exec($c);
if ($data === FALSE) {
die("Curl failed with error: " . curl_error($c));
}
$data = json_decode($data);
if (is_null($data)) {
die("json_decode failed with error: " . json_last_error());
}
foreach ($data->query->results->result as $r){
// do something with the data
}
$data is a decoded json response - it's got the data and it appears that my structure is right - i just want to loop through and display business names for example - but no go.
It should be $data->query->results->Result. Notice, the Uppercase Result.
To help you with JSON. Paste the whole JSON string into this utility, and see the tree structure visually.
json_decode requires you pass an extra boolean parameter if you want it to return an ARRAY rather than an object.
$data = json_decode($data,TRUE);
if (is_null($data)) {
die("json_decode failed with error: " . json_last_error());
}
foreach ($data['query']['results]'['Result'] as $r){
// do something with the data
}
Related
I am pulling data from a 3rd party web service and when the api goes under maintenance the json document no longer has the same structure (but is still a valid json document). So when I go to parse, I get an error: "Invalid argument supplied for foreach()" Makes sense, but how do I test for this and then call a separate function to log the error with the contents of the json document?
I tried adding set_error_handler("customError"); and that works but I don't know how to access the contents of $response or $json from the error function
$response = file_get_contents($url);
$json = json_decode($response, TRUE);
foreach($json['workers'] as $item) {
echo $item['address']; //address does not exist when in maintenance mode!
}
function customError($errno, $errstr) {
$link=Connection();
echo "<b>Error:</b> [$errno] $errstr ";
$sql="Insert into myErrors (response, description) values ('".$response."','.$errstr.');";
//echo $sql;
$result = mysqli_query( $link,$sql) or die('Error; ' . mysqli_error($link));
}
Test the result to see if the array exists before trying to loop over it.
$response = file_get_contents($url);
$json = json_decode($response, TRUE);
if (isset($json['workers'])) {
foreach($json['workers'] as $item) {
echo $item['address']; //address does not exist when in maintenance mode!
}
} else {
// insert something into myErrors table
}
This is my first time using web service. My PHP server get the json data from .net server where it is encoded to base64.
The problem now is, i failed to read each attribute inside the data:
Array ( [JSONDataResult] => {"file":"iVBORw0KGgoAAAANSUhEUgAAALUAAAEZCAYAAADR+mSIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABhuSURBVHhe7ZiBcuM4smz3\/3\/6PkrPjCgfppBMFWB53DgRx2whs4raMWJ7dv938H8\/KVGdjkR1qrNx+13ehftTU9w889V+vVOHqySq05GoTnU2br\/Lu3B\/aoqbZ77ar3fqcJVEdToS1anOxu13eRfuT01x88xX+\/VOHa6SqE5HojrV2bj9Lu\/C\/akpbp75ar\/eeT2cids\/O6cp6Xzad6zeR1PS+bSfovYfz+vhTNz+2TlNSefTvmP1PpqSzqf9FLX\/eF4PZ+L2z85pSjqf9h2r99GUdD7tp6j9x\/N6OBO3f3ZOU9L5tO9YvY+mpPNpP0XtP57XwwpzJ3E5Wd0n6fyn+93c4eZdTlyfuZOo\/HheDyvMncTlZHWfpPOf7ndzh5t3OXF95k6i8uN5PawwdxKXk9V9ks5\/ut\/NHW7e5cT1mTuJyo\/n9bDC3ElcTlb3STr\/6X43d7h5lxPXZ+4kKj+e18MKcydJc0pUZyRRnSr56ZwSl5O07+A+StLcSVR+PK+HFeZOkuaUqM5IojpV8tM5JS4nad\/BfZSkuZOo\/HheDyvMnSTNKVGdkUR1quSnc0pcTtK+g\/soSXMnUfnxvB5WmDtJmlOiOiOJ6lTJT+eUuJykfQf3UZLmTqLy43k9rDB3EpcT1\/90TtjvSlyewn2UqM5IkuZOovLjeT2sMHcSlxPX\/3RO2O9KXJ7CfZSozkiS5k6i8uN5PawwdxKXE9f\/dE7Y70pcnsJ9lKjOSJLmTqLy43k9rDB3Epc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x+oXd+2bws9BU1Y0\/N3TlTnZOaJXOb\/yCvfqF3z9\/t1c9JtzKr92pu8x\/j8YukJ6PswavzispGcy57xau5V+cnLt9sNpvNZrPZbDabzWaz2Ww2m81M\/ve\/\/wclQxXDBQHQjQAAAABJRU5ErkJggg==","fileSize":"8484","returnCode":"0"} )
There are 3 columns:
file
fileSize
returnCode
I have tried to get data using Object, Array or json but always failed.
//$json = json_decode($data, true); //array
//$json = json_decode($data); //object
//echo $result; //JSONDataResult
Below is one of the FAILED method. The full process coding:
<?php
if (isset($_GET['submit'])) {
$project_code = $_GET['project_code'];
$url = "http://1.2.3.4/to/file/process";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curl, curlopt_httpheader, array ("Content-type:application/json"));
$result = curl_exec($curl);
curl_close($curl);
$data = file_get_contents($url);
$json = json_decode($data, true); //array
//$json = json_decode($data); //object
//echo $result; //JSONDataResult
//print_r($json);
foreach ($json as $key => $value) {
if (!is_array($value)) {
//always goes here
echo "not array: ".$key . '=>' . $value . '<br/>';
} else {
foreach ($value as $key => $val) {
echo "is array: ".$key . '=>' . $val . '<br/>';
}
}
}
}
?>
Guys help me to read the content. I do not mind using which method as long as i can read each column inside the content. Many-many thank you.
[jangankecamsaya]
Assuming the data you posted in the question is the output of print_r($json);, it is clear that $json is an array that contains only one value (the big JSON) associated to the key JSONDataResult. It basically looks like this:
$json = array('JSONDataResult' => '{"file":"iVBORw0KGgoAAAANSUhEUgAAALUAAAEZCAYAAADR+mSIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABhuSURBVHhe7ZiBcuM4smz3\/3\/6PkrPjCgfppBMFWB53DgRx2whs4raMWJ7dv938H8\/KVGdjkR1qrNx+13ehftTU9w889V+vVOHqySq05GoTnU2br\/Lu3B\/aoqbZ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niztwoU7w7t\/nH4EWon+9k7Dy4M3eiMnYevDu32cjLcqIuzZ2z1TtP1Nlm8+1ivHuRRnMrdp6os80\/jrs4yUV6nFdP2OfnB3fO7s5t\/mFWXqTaeXfnu3Obf5RXl2HGRXI77u58d27zD\/K4CLRy55y5Oqu8yuu5yyv1XOWbzWaz2Wx+Feqv6vOs\/nV+evLq\/ORTmWKUbf4gry5IJe18KmPnwSjb\/FFGF+Ek7fx0dqLOTkbZ5o\/x+GUrK\/z8YNT56exEnZ2Mss0f487leNWpklH+KlO9k1F2os5ORtnmj3HncqQXiIy6NRu9d5SdqLOTUbb5Y9y5HOkFqox67j31s+s+UGcno2zzx7hzOd65QKdklD0Y5a+yes58lG02m81ms\/kI6q\/jevYq33+Nb34t6aUeZZvNr6BzqTebX8njkipP6p9P1Nlm82twl\/bVBd4Xe\/NrefdSP9gXe\/MrSS\/1KNtsfgXppX7wONsXerPZbDabTYPRv06cmcpH2QOV1RmVP1BZPWP24NX5g3ezzX+U85f56hdeqZ9H2cnj7E6v4vKT2hu9491s8we48wsddV5dkFfnilFWcTvr53ezzR\/gzi9UXYJTcp6NZpKsorJXc6PPrrv5j+N+oUn+6s+KUVfN3jlTn6snqrf5Q4x+oXd+2bws9BU1Y0\/N3TlTnZOaJXOb\/yCvfqF3z9\/t1c9JtzKr92pu8x\/j8YukJ6PswavzispGcy57xau5V+cnLt9sNpvNZrPZbDabzWaz2Ww2m81M\/ve\/\/wclQxXDBQHQjQAAAABJRU5ErkJggg==","fileSize":"8484","returnCode":"0"}');
A call to json_decode($json['JSONDataResult'], TRUE) decodes the big string into an array like this:
array(
'file' => 'iVBORw0KGgoAAAANSUhEUgAAALUAAAEZCAYAAADR+mSIAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAABhuSURBVHhe7ZiBcuM4smz3/3/6PkrPjCgfppBMFWB53DgRx2whs4raMWJ7dv938H8/KVGdjkR1qrNx+13ehftTU9w889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mFWXqTaeXfnu3Obf5RXl2HGRXI77u58d27zD/K4CLRy55y5Oqu8yuu5yyv1XOWbzWaz2Wx+Feqv6vOs/nV+evLq/ORTmWKUbf4gry5IJe18KmPnwSjb/FFGF+Ek7fx0dqLOTkbZ5o/x+GUrK/z8YNT56exEnZ2Mss0f487leNWpklH+KlO9k1F2os5ORtnmj3HncqQXiIy6NRu9d5SdqLOTUbb5Y9y5HOkFqox67j31s+s+UGcno2zzx7hzOd65QKdklD0Y5a+yes58lG02m81ms/kI6q/jevYq33+Nb34t6aUeZZvNr6BzqTebX8njkipP6p9P1Nlm82twl/bVBd4Xe/NrefdSP9gXe/MrSS/1KNtsfgXppX7wONsXerPZbDabTYPRv06cmcpH2QOV1RmVP1BZPWP24NX5g3ezzX+U85f56hdeqZ9H2cnj7E6v4vKT2hu9491s8we48wsddV5dkFfnilFWcTvr53ezzR/gzi9UXYJTcp6NZpKsorJXc6PPrrv5j+N+oUn+6s+KUVfN3jlTn6snqrf5Q4x+oXd+2bws9BU1Y0/N3TlTnZOaJXOb/yCvfqF3z9/t1c9JtzKr92pu8x/j8YukJ6PswavzispGcy57xau5V+cnLt9sNpvNZrPZbDabzWaz2Ww2m81M/ve//wclQxXDBQHQjQAAAABJRU5ErkJggg==',
'fileSize' => 8484,
'returnCode' => 0,
);
The value of file is encoded using base64. The complete code should look like this:
// Decode the JSON
$fileInfo = json_decode($json, TRUE);
// Decode the file content
$content = base64_decode($fileInfo['file']);
// Visually inspect its the decoded file content
print_r($content); // Congratulations, it's a PNG!
// Put the content in a file
file_put_contents('...the file path here...', $content);
// Use getimagesize() to learn about the image type
// an rename the file using the correct termination.
Btw, the value of fileSize is the length of the file field, i.e. the content encoded using base64, not the length of the actual PNG file on disk (as I would expect).
You tried to
$json = json_decode($data[0], true); //array
???
(mind the access on the first field on $data)
My code is:
$requesturl='https://blockchain.info/tx-index/1fda663d2584425f192eae045d3809950883ebe50f2222f98ef7d31f414f3f96?format=json';
$ch=curl_init($requesturl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$cexecute=curl_exec($ch);
curl_close($ch);
$result = json_decode($cexecute,true);
// to get the first i use
echo $result['out'][0]['addr'];
to get the second I use
echo $result['out'][0]['addr'];
Now my requirement is to look through the array using for each but its throwing error:
foreach ($result['out'] as $adressee) {
echo $adressee.'<br>';
}
for($i=0; $i<count($result['out']); $i++) {
echo $result['out'][$i]["addr"].'<br>';
}
Some Sample codes in PHP manual helped me come up with this solution
I'm trying to understand how to record the result of a curl GET request using php. I'm looking at outputing part or all of the result to mysql.
https://github.com/cloudtrax/docs/blob/master/api/code/php/simple_api_server_test_harness.php
function invoke_curl($method, $endpoint, $headers, $json) {
$api_server = 'https://api.cloudtrax.com';
try {
// get a curl handle then go to town on it
$ch = curl_init($api_server . $endpoint);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
if ($result == FALSE) {
if (curl_errno($ch) == 0)
echo "#### NOTE ####: nil HTTP return: This API call appears to be broken" . "\n";
else
throw new Exception(curl_error($ch), curl_errno($ch));
}
else
echo "RESULT: \n" . $result . "\n";
}
The $result shows like this:
{
"clients": {
"ssid2": 4,
"ssid1": 10
},
"rows": [
{
"time": "2016-03-23T02:45:00Z",
"ssid2": {
"traffic": {
"unclassified": {
// etc...
How can I associate each part of the result too a variable so I can then input too mysql?
It looks like this result in json format. You can use json_decode to decode it:
$resultObject = json_decode($result);
$clients = $resultObject->clients;
// ... get other data from result
The code below will convert the json into a PHP array. You can then use the indexes of the array to pull out values.
$result = json_decode($result);
$clients = $result->clients;
// Some MySQL queries
If your response is a JSON response then you can simply use php's json_decode to get parsed object.
$result = curl_exec($ch);
//to get associative array passing true
$jsonObj = json_decode($result, true);
$clients = $jsonObj['clients'];
$rows = $jsonObj['rows'];
You can refer to these answers for more detail:
Parsing JSON object in PHP using json_decode and
Parsing JSON file with PHP
I need to query SocialMention.com for "Colorado Springs" and "District 11" and pull the data back into a CSV file. I'm an old programmer but new to PHP and JSON. Here's the simple php code:
<?php
$curl = curl_init('http://api.socialmention.com/search?q=%22colorado+springs%22+%22district+11%22&f=json&src[]=twitter&sentiment=true&meta=info');
$result = curl_exec($curl);
echo $result;
?>
How do I parse $result and store it in a CSV file? I've been researching this for 6 days and have tried every example I can find with no luck. In the examples below I keep getting an "Invalid argument in foreach" error.
Your question is broad since you don't really say how you want to parse $result, but you're not even getting $result because curl_exec will actually print out its contents. Instead you can set curl_setopt($curl, CURLOPT_RETURNTRANSFER, true), or you can probably just use$result = file_get_contents($url);
Anyway, you can change the result from JSON to usable PHP data structure via $data = json_decode($result, true). The second argument forces associative arrays, which are probably better for your purposes.
Then you can write to the CSV file:
$fh = fopen('csvfile', 'w');
foreach ($result['items'] as $items) {
fputcsv($fh, $items);
}
u can refer the two links too
1.Parsing JSON file with PHP
2.php writing to csv from an array
$json_a=json_decode($string,true); //decodes json
//writes to csv
$fp = fopen('file.csv', 'w');
for ($i = 0; $i < count($json_a); $i++) {
$fields = //json object feids here
fputcsv($fp, $fields);
}
fclose($fp);