I have been searching the internet for hours now, and i can't figure it out.
<?php
$json = '{"pages":[{"name": "Page1","inputs":[{"title": "Catagory","name": "catagory","type": "radio","options":[{"name": "Paper","value": "paper"}{"name": "Letter","value": "letter"}]}{"title": "Title","name": "title","type": "text"}{"title": "File","name": "file","type": "file","fileName": "?pages[0].inputs[0]"}{"title": "Submit","type": "submit"}]}]}';
$result = json_decode($json, true);
var_dump($result);
echo $result['pages'][0]['name'];
echo $pages[0]['name'];
?>
Im just simply trying to parse some json but the website says this:
NULL
Notice: Undefined variable: pages in C:\Users\hazzj\Desktop\Stuff\Apache-Server\htdocs\WMS\Author\submit\test.php on line 7
You'd missed out commas between strings {}. Use this modified $json variable:
$json = '{"pages":[{"name": "Page1","inputs":[{"title": "Catagory","name": "catagory","type": "radio","options":[{"name": "Paper","value": "paper"},{"name": "Letter","value": "letter"}]},{"title": "Title","name": "title","type": "text"},{"title": "File","name": "file","type": "file","fileName": "?pages[0].inputs[0]"},{"title": "Submit","type": "submit"}]}]}';
$result = json_decode($json, true);
echo $result['pages'][0]['name']; // Output: Page1
echo $pages[0]['name']; // Not sure what this $pages variable is
Related
I'm a beginner in json please help
I'm trying to access value of certain objects from an online published json file via php script and not able to do so following the examples from this forum
<?php
$str = file_get_contents('http://data.companieshouse.gov.uk/doc/company/02050399.json');
$json = json_decode($str, true);
$companyname = $json["primary topic"]["CompanyName"];
print $companyname;
?>
i get the following error
( ! ) Notice: Undefined index: primary topic in C:\wamp\www\json.php on line 4
Call Stack
# Time Memory Function Location
1 0.0000 244456 {main}( ) ..\json.php:0
I have tried single and double quotes, [0] for array but to no avail
You should have to use primaryTopic :
$str = file_get_contents('http://data.companieshouse.gov.uk/doc/company/02050399.json');
$json = json_decode($str, true);
$companyname = $json["primaryTopic"]["CompanyName"];
print $companyname;
Output will : ZENITH PRINT (UK) LIMITED
I think you had a mistake at 'primary topic' key. The key-name i saw in the response is 'primaryTopic'. Could you please check again?
I am trying to run a php script in terminal to get a organized reply of cryptocurrency data. the full JSON array can be viewed at https://poloniex.com/public?command=returnTicker. The nested array isnt stacked with [] and parsing this format is becoming troublesome.
here is the code i used:
$fgc = json_decode(file_get_contents("https://poloniex.com/public?command=returnTicker"), true);
echo "Last Price: $".$fgc["last"]." Ask: ".$fgc["lowestAsk"]." Bid: ".$fgc["highestBid"];
echo PHP_EOL;
This is the error it gives me:
PHP Notice: Undefined index:
I have a feeling i need to define each coin however im not sure how to parse it.
other code i have tried:
$fgc = json_decode(file_get_contents("https://poloniex.com/public?command=returnTicker"), true);
$data = $fgc["BTC_BCN"];
foreach($data as $details){
echo "".$details["last"]." ".$details["lowestAsk"];
echo " ".$details["highestBid"];
echo PHP_EOL;
}
The error for this code is:
PHP Warning: Illegal string offset
Please help me understand how to parse this format. Thank you.
I have this JSON (is from Steam Market):
{"success":true,"lowest_price":"$5.79","volume":"2,932","median_price":"$5.79"}
And I have this code:
$urlm = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name='.$name;
$market = json_decode(file_get_contents($urlm), true);
echo $market['lowest_price'];
But when I try it, they give me an error:
Notice: Undefined index: lowest_price
What is wrong? Because I have an other JSON with the same method and works perfect.
You should urlencode your varaiable:
$urlm = 'http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name='. urlencode($name);
Hi I have this json code
{"points":[ {"10":"10"}, {"1":"1"} ]}
and this is my php code
$pointsfirst = $row['points'];
$points = json_decode($pointsfirst,true);
$getit = $points['points'][1]['10'];
echo $getit;
$row['points'] is from my database where I have stored the json
and I keep getting this error
Notice: Undefined offset: 10 in
/Applications/MAMP/htdocs/projectg/getpointsapi.php on line 46
what am I doing wrong ??
Right way is:
$getit = $points['points'][0][10];
echo $getit;
Try
$getit = $points['points']['1']['10'];
with the quotas! instead...
Arrays in PHP start with offset 0, not 1. This means you should probably use $getit = $points['points'][0]['10']; instead.
I'm having trouble sending data via sessions because I'm getting errors of undefined variable while defining the variable in controller/checkout/shipping_address.php under validate() function. (checkout/shipping_address/validate).
$this->session->data['ship_date'] = $this->request->post['ship_date']; //<- line 102
In controller/checkout/shipping_method
$ship_date = $this->session->data['ship_date'];
if(empty($ship_date)) echo "var empty";
$ship_date = explode("-", $ship_date);
$ship_date = $ship_date[0] . "/" . $ship_date[1] . "/" . $ship_date[2];
and then I do
$quote = $this->{'model_shipping_' . $result['code']}->getQuote($shipping_address, $ship_date);
Also yes, in model/shipping/fedex.php I allow usage of $ship_date parameter. Yet after that I get.
Invalid JSON: Notice: Undefined index: ship_date in
/var/www/catalog/controller/checkout/shipping_address.php on
line 102[] parsererror Notice: Undefined index:
ship_date in
/var/www/catalog/controller/checkout/shipping_address.php on
line 102[]
You should debug the arrays $this->session->data and $this->request->post.
The reason you see those errors is that there is no index ship_date in $this->session->data and in $this->request->post. So you get a Notice: Undefined index:.
Because of the notices that are printed your afterwards outputted json becomes invalid.
Actually, OpenCart only talks through JSON. So adding this will help.
$JSONarray = array("date" => $this->request->post['ship_date']);
$this->session->data['ship_date'] = json_encode($JSONarray);
When you want to use it,
$JSONarray = $this->session->data['ship_date'];
$arr = json_decode($JSONarray, TRUE);
$Value = $arr['ship_date'];
We have to make the data JSON and then send it