How to Deserialize a json encoded array in php [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have some problem in the following array, I want to access the value of the "videoid" from the given array that is been fetched with json_encode
Array ( [0] => {"DATA":[{"videoid":"462"}]"});
Please help me so that I can fetch the value of "videoid".

If you have a php string containing JSON and you want to access the videoid property use php's json_decode function :
$json='{"DATA":[{"videoid":"462"}]}';
$array=json_decode($json);
var_export(current($array->DATA)->videoid);//returns '462'
See the code in action here :
http://sandbox.onlinephpfunctions.com/code/485b94b6423972b8c87eec885da8fdc5a56c6acd

Here you are. Should work.
If you only want one value I would suggest you make sure to get the json in a different format if possible:
$array[0]->data[0]->videoid;
If you have more videoids in your DATA than you need to loop it to get it
foreach($array[0]->data as $key => $value){
$dosomethingwithit = $value;
}
Hope it helps

Related

How to get json key as value instead string with json_encode function use [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
I am trying to convert php array to json using
json_encode()
By using this I am getting
[{"s":"simple2","value":"simple2","i":"img","u":"url","p":"520.000000"}]
Instead of key as string I wants this data in below format
[{s:"simple2",value:"simple2",i:"img",u:"url",p:"520.000000"}]
How to get this type of data ? Is it possible to get this type data?
json_encode() will produce only a valid json format which is really the one it is producing. The one that you want is not a valid json format. You will have to apply text processing to get what you need. However, what is your final goal with the output of json array? Most languages that can can process json will accept the valid format.

Python equivalent of the PHP stdClass [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Coming from PHP, I love the pythonic syntax.
Is there a Python equivalent of the PHP stdClass?
Edit:
I want to point out I'm looking for a specific data type in Python to store data like the stdClass in PHP. So not in a dict, list, array, .. but in an object. Does there exist a specific data type in Python to store only data that behaves like an object?
You can do:
class StdClass:
pass

How to insert php post name into a variable? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have a post value named $_POST['John'] and I want to insert the post name "John" into a variable but not its value. How can I achieve this? Code Sample:
$_POST['John'] = "value";
array_keys is PHP function which is returning the keys from an array, you have only single array than we can use 0 as the key. if you have more than one array element you can use loop.
You can use array_keys as you mentioned there is one parameter use
$a = array_keys($_POST)[0];
https://3v4l.org/NUkkL

How to extract data from this JSON ? (PHP) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
[{"id":"1",name":"Test 1","players":"999"},{"id":"2","name":"Test 2","players":"100"}]
How do I print pull data?
Your json is invalid (missing a quote). I fixed it below.
$j='[{"id":"1","name":"Test 1","players":"999"},{"id":"2","name":"Test 2","players":"100"}]';
$a=json_decode($j,true);
print_r($a);
Use json_decode. The "true" value makes it return an associative array.
Your data that you're trying to use has an error. In the first object, "name" has no opening quotation. Use PHP's json_decode functionality after you correct that error.
Note: You should be able to pass the json data as a variable into the function with the boolean value set to true and for now just run a print_r to view your data as it's decoded.

Recreating a dynamic php array [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a php array which is created from data in an sql database.
All I want to do is recreate that identical array on another site.
I can print_r it no worries. But how would I output the structure of the array so that I can go as follows on the new site.
$newvar = array(.....);
I'm sure it's a very simply question, But I can't find an answer.
serialize Try this function. I think this is what you need
you can use json_encode to send your array and keep the structure of your array.

Categories