简体   繁体   中英

Turning an indexed array to json object in PHP

When I use json_encode I get one large array filled with objects. How do I get the result to return many json objects.

eg

current result

[{data1}, {data2}, {data3}]

the result i want

{{data1}, {data2}, {data3}}

Snippet of my current code

        $obj = json_decode($response);
        $list_of_obj = $obj->{'profiles'}->{'profile'}; // returns an array of json objects

        foreach($list_of_obj as $prov)
        {
            $list_of_prov[] = $prov;
        }

        file_put_contents('./results/profiles/' . time() . '-' . $count . '.json', json_encode($list_of_prov, true));

if you have a set of JSON objects this will generate an array of objects in PHP.

Here you are some documentation to help you: http://json.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM