How to extract data from this JSON ? (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
[{"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.

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.

Is it possible to json_decode a json data with base64 encoded data in it? [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 2 years ago.
Improve this question
I have a json data looks like the below fig.
Notice the "img" key holds a base64 data.
Im using php to do this.
Yes it is totally possible to decode the json data containing base64_encoded data as long as it is a valid json format.You can always use json_decode to decode the data or base64_encoded string received from the server.

PHP json_decode() return null [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I am using cloudinary to upload images.I am trying to decode json string generated by image upload plugin but it return null.I'm new to json plese help
Here is json string
[{"public_id":"pdf/Eagle_s_Crest_s1khaa","version":1552905253,"signature":"976a2475ba858beeb33d533b4bdd897c7730574c","width":3543,"height":5315,"format":"png","resource_type":"image","created_at":"2019-03-18T10:34:13Z","tags":[],"bytes":579592,"type":"upload","etag":"9c1ce7ee6f0d1a7ff540d9e06cfbc2bf","placeholder":false,"url":"http://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","secure_url":"https://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","access_mode":"public","existing":false,"original_filename":"Eagle ◀"
It is returning null because it's not valid JSON. It's missing a } and a ] on the end.
Compare here:
<?php
var_dump(json_decode('[{"public_id":"pdf/Eagle_s_Crest_s1khaa","version":1552905253,"signature":"976a2475ba858beeb33d533b4bdd897c7730574c","width":3543,"height":5315,"format":"png","resource_type":"image","created_at":"2019-03-18T10:34:13Z","tags":[],"bytes":579592,"type":"upload","etag":"9c1ce7ee6f0d1a7ff540d9e06cfbc2bf","placeholder":false,"url":"http://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","secure_url":"https://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","access_mode":"public","existing":false,"original_filename":"Eagle ◀"'));
var_dump(json_decode('[{"public_id":"pdf/Eagle_s_Crest_s1khaa","version":1552905253,"signature":"976a2475ba858beeb33d533b4bdd897c7730574c","width":3543,"height":5315,"format":"png","resource_type":"image","created_at":"2019-03-18T10:34:13Z","tags":[],"bytes":579592,"type":"upload","etag":"9c1ce7ee6f0d1a7ff540d9e06cfbc2bf","placeholder":false,"url":"http://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","secure_url":"https://res.cloudinary.com/dowh9bxad/image/upload/v1552905253/pdf/Eagle_s_Crest_s1khaa.png","access_mode":"public","existing":false,"original_filename":"Eagle ◀"}]'));
Either you pasted here the wrong JSON, or the upload plugin is returning invalid JSON.
If you use json_decode , i suggest you look at the doc : http://php.net/manual/fr/function.json-decode.php
Since we don't have your PHP code here i suppose that the second parameter "assoc" is not included in your code and may be the reason of your troubles

How to Deserialize a json encoded array in 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
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

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