How to extract value from json [duplicate] - php

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 1 year ago.
I have this json
{"response":{"status":"SUCCESS","totalsent":1,"cost":2}}
Now I want to extract the value of "status"
Please how can I do this in php?

$yourJson = '{"response":{"status":"SUCCESS","totalsent":1,"cost":2}}';
$jsArr = json_decode($yourJson, true);
print_r($jsArr['response']['status']);

Related

How to extract decode JSON from REDCap Array with PHP [duplicate]

This question already has answers here:
Why does this PHP code just echo "Array"?
(6 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 2 years ago.
I have an JSON Export from a REDCap and it started as a nested ARRAY. I use json_decode, but when I print the result I get an ERROR.
Here is the Array:
[{"record_id":"13","lastname":"Mustermann","first_name":"Json","dob":"1948-10-12","case_number":"1366613"}]
My Code is:
$deco = json_decode($json);
print $deco;
The line "echo" gives an error. What am I doing wrong?!
Thank you

How to convert a response to an appropriate form? [duplicate]

This question already has an answer here:
How to extract and access data from JSON with PHP?
(1 answer)
Closed 4 years ago.
I use Binance API.
The PHP function gets file contents of url:
https://api.binance.com/api/v1/klines?symbol=BTCUSDT&interval=4h&limit=1
I receive such a response:
[[1528545600000,"7635.01000000","7650.00000000","7566.00000000","7621.15000000","3246.04484200",1528559999999,"24674635.12120312",57351,"1932.28202000","14685353.70584041","0"]]
How to get the second value? (7635.01000000)
If you want to get the second value use this:
$receivedData = '[[1528545600000,"7635.01000000","7650.00000000","7566.00000000","7621.15000000","3246.04484200",1528559999999,"24674635.12120312",57351,"1932.28202000","14685353.70584041","0"]]';
$jsonDecodeData = json_decode($receivedData);
$secondValue = jsonDecodeData[0][1];
echo $secondValue; //7635.01000000

PHP Get Array Value from JSON Not working [duplicate]

This question already has answers here:
How to loop through PHP object with dynamic keys [duplicate]
(16 answers)
How to extract and access data from JSON with PHP?
(1 answer)
Closed 5 years ago.
I want to get the URLS from the JSON below.
$jsonArray = {
"uuid": "signed",
"PreSigned": "{'url': ['www.g.com', 'www.o.com']"}
I tried this $jsonArray -> PreSigned[0]->url
And it didn't work

I want to extract the number by key from a query string. [duplicate]

This question already has answers here:
Parse query string into an array
(12 answers)
Closed 7 years ago.
This is the value i get from db.
pkid=1&ordernumber=54322&ordervalue=12345&response=2&scheduleId=1
Want to extract response from this.That is 2.
Here it is
$str ='pkid=1&ordernumber=54322&ordervalue=12345&response=2&scheduleId=1';
parse_str($str);
echo $response; // output :- 2

Split set of data in the output using PHP [duplicate]

This question already has answers here:
json decode in php
(5 answers)
Closed 8 years ago.
How to spit this set of data using php? this data generated from some php to my mysql database.
[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]
now i just need to get id=2 and its value in the output.
It is a JSON data.Try with -
$array = '[{"id":"1","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Company","value":"Destination Queenstown"},{"id":"2","is_email":"false","add_to_day_hour_info":"false","add_to_day_hour_body":"false","translation":"Your Name","value":"Ella Zhang"}]';
$array = json_decode($array);
echo $array[1]->id;

Categories