开发者

JSON Encode Help

Currently, I have a JSON encoded array that looks like this:

[
{
    "username1": {
        "post": {
            "some_key" : "some_value"
        }
    }
},
{
    "username1": {
        "post": {
            "some_key" : "some_value"
        }
    }
}
]

But how can I make it so that the jso开发者_开发技巧n follows this pattern:

username -> array_of_posts -> post -> values

instead of the current pattern?

Thanks

Here is my current code:

    while ($row = mysql_fetch_assoc($query)) {
            $row['username'] = $username;
            $returns[][$username]["post"] = $row;
        }
    }   
    echo json_encode(array_values($returns));


$returns[$username][] = $row;

echo json_encode($returns);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜