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
Related
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.
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.
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 wanna decode a Json data using PHP, that is returned by an URL. Here is my Json data returned by an URL;
a:1:{s:7:"country";s:10:"United States";}
Any help will be appreciated
Thanks, ^_^
As pointed out in the comments, your data is not JSON. I wanted to clarify what this format is. This is PHP's native serialization format.
php > $array=["country"=>"United States"];
php > var_dump(serialize($array));
string(41) "a:1:{s:7:"country";s:13:"United States";}"
Technically, you could de-serialize it, but coming from an un-trusted source, that would be a security risk. Are your sure your data source is returning this(if so, that is highly suspect)? Is it possible something earlier in your code is serializing the value that has already been parsed?
You can use json_decode() function of PHP.
<?php
$jsonobj = '{"Peter":35,"Ben":37,"Joe":43}';
var_dump(json_decode($jsonobj));
?>
P.S: maybe the format of your json data is wrong.
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.
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 am calling an an event handler in jquery for search. search value appends with url string in jquery and send it php.
my original url
www.sit.com/index.php?search=a&b
i encode this search string with
var search = encodeURIComponent(search);
www.site.com/index.php?search=(encoded search)
but i don't know how to decode this search string to execute. Please help how to decode this string in php. Thanks
Use the urldecode(your_string) function.