How to create a array using json value - php

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

Related

Get Json Value with extra quotes using 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().

How to parse stdClass object in php

Using var_dump from an API call give me the output like this
How to put them into an array? thanks
You can use json_encode to convert it to a json. After which you can use json_decode with the second parameter set to true which will return an array instead of an StdObject.
If the api you're calling simply returns a json itself then you can go ahead and use json_decode directly with the second argument set to true to yield the same result.
There are other ways, but this is the simplest.
You can check out other questions, like this one or this one.

Decode JSON from received POST Array

I sent POST request to my web-server with a few JSON-Params within the params there is an array. I receive for in the POST array-variable:
$ids = $_POST['id_arr']; // contains: [{\"id\":12},{\"id\":13}]
I don't know how to parse this to an array in PHP. I tried to solve it with json_decode, but it seems like the wrong way.
My desired result is this: $ids = array(12, 13);
How can I do this?
You need to tell the json_decode function to convert the objects to associative arrays. As shown in the json_decode documentation, this can be done by setting to true the second argument:
$ids = json_decode($_POST['id_arr'], true);

interpreting JSON with PHP and putting it in array

I have only worked with JSON once before, but I don't recall how to use it with PHP.
If I have a script that returns JSON like this:
{
"bunisess":[
"business",
"bonuses",
"burnooses",
"boniness",
"burnoose's"
]
}
how can I take that and make each value a value in a PHP array. The keys just being numbers from 0 onwards?
Use json_decode, but pass true as the second parameter to get an associative array back:
$json='{"bunisess":["business","bonuses","burnooses","boniness","burnoose\'s"]}';
$data=json_decode($json, true);
Now, you can use array_values to get a numerically indexed array as you required:
$data=array_values($data);
A simple google search could have lead you to this page : http://php.net/manual/fr/function.json-decode.php
The subarray will be respecting exatcly what you're asking for.
Assuming that $data is the complete JSON string
$stdObject = json_decode($data, true);
print_r($array);
You should get an array with one key bunisess and value another numeric array with the other values.

How receive json object from client into a php 2D array at server?

I want to fill a 2D array in php from a JSON object in javascript at client. Can anybody help me to do this functionality?
From the top of my head, without knowing anything about your code
you could use json_decode
use it like this:
$array = json_decode($_POST['data'], true);
#check the second parameter set to true, otherwise you will get a stdclass.
json_decode()
http://php.net/manual/en/function.json-decode.php

Categories