http://simsimi.com/getRealtimeReq?uuid=VbQqwsQ3qiCw1T04VrrFQzBBlkfZibg3YFkbWz6VquZ&lc=id&ft=1&reqText=Eh+jelek&status=W
How to get value from respSentence
Im using php lang ^_^
" {"status":200,"respSentence" 11 \:"respSentence"}"` is not valid json. Use some online sites to validate your json and try like this,
$json = '{"status":200,"respSentence" :"iyas"}';
$array = json_decode($json, true);
echo $array ['respSentence'];
You can try using file_get_contents and json_decode PHP functions
$url = "http://simsimi.com/........";
$data = file_get_contents($url);
$json = json_decode($data, true);
echo $json ['respSentence'];
hope it helps
I have code here that will get json data using curl. Now I want to echo all data. This will show no output.
<?php
$json = file_get_contents('myurl');
$data = json_decode($json);
print_r($data);
?>
This is json coming from my url:
({"Response_Code":"0000","ResultMobilePrefix":["0917","0905","0906","0915","0916","0926","0927","0937","0935","0817","0936","0922","0923",
"0932","0933","0934","0942","0943","0907","0908","0909","0910","0912","0918","0919","0920","
0921","0928","0929","0930","0938","0939","0948","0949","0925","0989","0999","0947","0998","
0946","0975","0977"]});
All you need is
echo json_encode($json);
Use true to convert it into array;
$data = json_decode($json,true);
echo '<pre>';
print_r($data);
for displaying json in format use json_encode() and for proper format use JSON_PRETTY_PRINT
header('Content-type: application/json');
echo json_encode($json,JSON_PRETTY_PRINT);
you need to get rid of the bracket and semicolon on the JSON file first before you can use the json_decode();
<?php
$json = file_get_contents('myurl');
//remove the brackets
$json = str_replace("(", "", $json);
$json = str_replace(")", "", $json);
//remove the semicolon
$json = str_replace(";", "", $json);
$data = json_decode($json);
print_r($data);
?>
this is a bit ugly, but hope you get the idea, you need to remove that character first
I just want to add to what Manish has explained above. This is what PHP Docs say about the second parameter:
When TRUE, returned objects will be converted into associative arrays.
else you will simply get a stdclass object
The problem is the URL does not return a valid Json
you could simply try
var_dump($data);
this will return null because it's not a valid json see json_decode
this will work
$json = file_get_contents('myurl');
$json = preg_replace('/[ ]{2,}|[\t\n\r\(\)\;]/', '', trim($json));
$data = json_decode($json);
print_r($data);
<?php
$url = "http://api.giphy.com/v1/gifs/search?q=hello&api_key=dc6zaTOxFJmzC";
$content = file_get_contents($url);
$json = json_decode($content);
echo $json->images[0]->fixedheight->url[0];
?>
I've tried everything- even reading it as an array and it doesn't work.
Any help?
So sorry to bother! Thanks again.
You should access it this way
echo $json->data[0]->images->fixed_height->url;
That is beacause the $data is an array , and it has an object as its first parameter.
use this
<?php
$url = "http://api.giphy.com/v1/gifs/search?q=hello&api_key=dc6zaTOxFJmzC";
$content = file_get_contents($url);
$json = json_decode($content);
echo "<pre>";
print_r($json->data[0]->images->fixed_height->url);
exit;
?>
json response as below:
{"Success":true,"ErrorCode":0,"UserInformation":{"UserID":"19"}......
how do I get the UserID value by using json_decode?
I tried the below code with no luck.
$Response = json_decode($Response[2]);
echo $Response[0][0][0];
This should work:
<?php
$json = '{"Success":true, "ErrorCode":"0","UserInformation":{"UserID":"19"}}';
$response = json_decode($json, true);
echo $userId = $response["UserInformation"]["UserID"];
?>
Please check the PHP documentation of json_decode at http://php.net/json_decode
You can use object as well if you skip the second parameter of the json_decode function.
I would like to trnsform some JSON data to a php array, this is my code:
<?php
$obj1=json_decode('http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json', true);
$championname = $obj1[data][aatrox][name];
echo $championname;
?>
The problem is that i don't know how to get the data from http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json
How can i make this code work?
Try with file_get_contents() like this:
$json = file_get_contents('http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json');
$obj1 = json_decode($json , true);
$championname = $obj1['data']['aatrox']['name'];
echo $championname;
Use file_get_contents to download a file.
$json = file_get_contents('http://ddragon.leagueoflegends.com/cdn/3.15.5/data/en_US/champion/Aatrox.json');
$obj1 = json_decode($json, true);