Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
235 views
in Technique[技术] by (71.8m points)

如何将多维数组输出成为json?

数组使用json_encode后输出:

[
   {
     volumesId: 2,
     volumeTitle: "第一章 打死你个废物!",
     volumeType: 3,
     chapterCount : "",
     chapters: 
        {
            chapterId: 20377,
            vip: 0,
            title: "第一章 打死你个废物!",
            chapterNumber: 2
         }
    },
    
    {
     volumesId: 3,
     volumeTitle: "第二章 强势逆袭",
     volumeType: 3,
     chapterCount : "",
     chapters: 
        {
            chapterId: 20378,
            vip: 0,
            title: "第二章 强势逆袭",
            chapterNumber: 3
        }
    },
    
    {
     volumesId: 4,
     volumeTitle: "第三章 那个女人我要了",
     volumeType: 3,
     chapterCount : "",
      chapters: 
        {
            chapterId: 20379,
            vip: 0,
            title: "第三章 那个女人我要了",
            chapterNumber: 4
        }
    }
]

请问如何将

chapters: 
{
    chapterId: 20378,
    vip: 0,
    title: "第二章 强势逆袭",
    chapterNumber: 3
}

转化为:

chapters: 
[
    chapterId: 20378,
    vip: 0,
    title: "第二章 强势逆袭",
    chapterNumber: 3
]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

JSON.stringify(data);

输出黏贴上去就好了,
或者找个格式化的公共网站


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...