douzhu7507 2013-11-15 17:10
浏览 89
已采纳

格式化我的输出JSON更可读

This is my current PHP code

while ($row = mysql_fetch_array($result)) 
    {
        $post = new Post();
        $post->setId($row['post_id']); 
        $post->setBody($row['post_body']); 
        $post->setImage($row['post_imgurl']);
        $post->setStamp($row['post_stamp']);
        $postList[]  = $post;
    }
    return array('post'=> $postList);
}

and this is its output JSON. How can i make my JSON more readable like below and remove / the character?

More readable output:

ExtraCharacterandJSONFormat

  • 写回答

2条回答 默认 最新

  • dongziduo9762 2013-11-15 17:16
    关注

    If you want readable JSON, then read it in a tool designed to present JSON for reading (such as the Chrome JSONView extension). Don't try to munge raw data into particular patterns.

    That said, you can persuade PHP to munge the data in that fashion with:

    json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?