Get Json Value with extra quotes using php - php

Get all value from json using json_decode. Given name is Juliet"es this json. If using json_decode this array will be change null value. how do i get this json to array
$jsonobj = '{"Name":"Juliet"es","Maths":37,"English":43}';
if anyone having any idea please post answer.

Try $convertedJson = json_decode(addslashes($jsonobj));.
But has suggested by #Barmar and #CBroe , always generated JSON strings from array or object with json_encode().

Related

PHP json_encode encode only a key

As an API response to a payment gateway I receive an object, I would like it to become json so I used json_encode, but I only get the first key.
json_encode convert only the first key cause array is too large
json_encode convert array to json
json_decode convert json to array
API’s by default must give you a json and you must decode json data to array if you are going to use it on back-end.
Show some code, so we can help you

Not sure why I can't get the values of this array or decode the json

I am making a call to an API which should return a JSON array. I receive this:
Array
(
[0] => {"msg_id":"0t5OxT1ZP9VcF45L2","_text":"I want to reserve","entities":{"intent":[{"confidence":1,"value":"make_reservation","type":"value"}]}}
)
I know it's JSON because a) the docs say that's what I should be getting and b) I ran isJson($response) and got true.
I have tried to use json_decodebut the code just dies when I do (it errs saying it's expecting a string and got an array which makes sense but if I do json_encode that would just further encode the json from what I can understand).
As I understand it, I just need a way to traverse this array and get the "value:" key inside entities: intent:. However I can't figure out how to get it or where I'm wrong.
I have tried doing:
$val = $jsonArray[0]['entitites']['intent'][0]['value'] but nothing comes out.
You are trying to decode a PHP array that has encoded values.
You should try json_decode($jsonArray[0]) instead, so that you decode the value of the first array key, as that is the actual json string.
The data you posted is a php array where the value of the first element of the array is a json string.
json_decode($response[0]);

PHP display array in array in array

I want know how to access to array in array in array in php.
The result with $user is this:
'pages':{'x','y','z','access':{'a':3,'b':6,'c':8,'contact':2}}
How I can access to contact, please?
First of all this is JSON (probably), so before we can access it with php we need to decode it using json_decode which will give you a php object. (i made it valid JSON)
$jsonString = '{"pages":{"x": 0,"y": 0,"z": 0,"access":{"a":3,"b":6,"c":8,"contact":2}}}';
$phpObject = json_decode($jsonString);
var_dump($phpObject->pages->access->contact);
// prints int(2)
Use json_decode to convert this to array in PHP (if it is JSON)
It seems your string missing {} around.
{
"id":1,"active":1,"canAccess":{"entities":{"1":{"name":"blablabla","services":{"‌​45":{"name":"xxx"}}}}},"blabla":null,"pages":{"acces":{"notifications":1,"contact‌​":2}}
}
then it is a valid JSON string.
var_dump(json_decode($string,true));

How to create a array using json value

I have a json record like blow
[{"low":null,"high":10,"type":2,"value":0},{"low":10,"high":60,"type":1,"value":10},{"low":60,"high":null,"type":2,"value":11}]
I would like to create array using this. i tried json_decode its not help i just want create a associative array from this json
any help
thank you
Make sure you're passing true to the second parameter in json_decode(), which specifies that you want an associative array returned.
$arr = json_decode($string, true);
Parameters
assoc
When TRUE, returned objects will be converted into associative arrays.
see this page : http://php.net/manual/en/function.json-decode.php
use json_decode with this format : json_decode($value,true);
your code : http://pastebin.com/4vdVHjQN

Help editing JSON to make an array rather than a 'dictionary'

I currently have json using json_encode from a mysql query which looks like this:
{"post_2":{"caption":"...","id":"...","accountID":"..","date":"07\/07\/2011 1:45:12 AM","title":"...","authorInfo":{"Email Address":"..."}}}, {"post_2":{"caption":"...","id":"...","accountID":"..","date":"07\/07\/2011 1:45:12 AM","title":"...","authorInfo":{"Email Address":"..."}}}
How can I have the json being an array of posts ('post_2', 'post_1') rather than it being a dictionary? The JSON will be decoded on an iPhone using SBJSON and the JSON will have to be made into an array in the backend.
Thanks in advanced.
Provide a non-associative array to json_encode(). The easiest way is usually to simply call array_values() on the (associative) array, and encode the result.
Take a look at PHP's json_decode function, specifically the 2nd parameter if you want an array.

Categories