-3

以下のような形式でjsonを生成できるスクリプトを書きたいと思います。

[
        [ "20 aug 2013",                                      
            [
                {lbl1: "Titanium Card",lbl2: "$2000",lbl3: "$400",img1234:"checkboxwhite.png"}, 
                {lbl1: "Gold Card",lbl2: "$1000",lbl3: "$500",img1234:"checkboxwhite.png"}, 
                {lbl1: "Silver Card",lbl2: "$800",lbl3: "$600",img1234:"checkboxwhite.png"}
            ]
        ],

        [ "22 aug 2013",                                               
            [
                {lbl1:"Savings 1", lbl2: "$400",lbl3:"N/A",img1234:"checkboxwhite.png"},
                {lbl1: "Savings 2", lbl2: "$400",lbl3: "N/A",img1234:"checkboxwhite.png"}

            ]
        ],
        [ "24 aug 2012",
            [                                                     
                {lbl1: "Checking 1",lbl2: "N/A",lbl3: "$400",img1234:"checkboxwhite.png"},
                {lbl1: "Checking 2",lbl2: "N/A",lbl3: "$400",img1234:"checkboxwhite.png"}
            ]
        ]     
    ];

Json オブジェクト:

var jsonObj= {"20th Aug 2013":[{"agenda":"Eventbuilder program session for next events","endtime":"20th Aug 2013 16:00 pm","starttime":"20th Aug 2013 09:00 am","status":"1","location":"Sardar Patel Stadium, Ahmedabad, Gujarat","speaker":"Salim Kg","parent":"0","type":"Entertainment","lang":"72.5644771","id":"1","title":"Eventbuilder program session","isAttend":0,"app_id":"2","speaker_id":"1","lat":"23.0419169","floor_plan":"floorplan_2.png","handoutfile":"test1.pdf"}],"18th Aug 2013":[{"agenda":"entertainment weekly events","endtime":"18th Aug 2013 16:00 pm","starttime":"18th Aug 2013 09:00 am","status":"1","location":"GMDC Ground Counter1,Ahmedabad","speaker":"Salim Kg","parent":"0","type":"Entertainment","lang":"72.5669487","id":"2","title":"Eventbuilder Team meeting ","isAttend":1,"app_id":"2","speaker_id":"1","lat":"23.0400935","floor_plan":"floorplan_3.png","handoutfile":""}],"17th Aug 2013":[{"agenda":"entertainment weekly events","endtime":"17th Aug 2013 16:00 pm","starttime":"17th Aug 2013 09:00 am","status":"1","location":"GMDC Ground Counter2,Ahmedabad","speaker":"Salim Kg","parent":"0","type":"Entertainment","lang":"72.5644771","id":"3","title":"8th International Workshop on Commercial Law","isAttend":1,"app_id":"2","speaker_id":"1","lat":"23.0419169","floor_plan":"","handoutfile":"sc3.pdf"}],"16th Aug 2013":[{"agenda":"entertainment weekly events","endtime":"16th Aug 2013 16:00 pm","starttime":"16th Aug 2013 09:00 am","status":"1","location":"Sardar Patel Stadium, Ahmedabad, Gujarat","speaker":"Salim Kg","parent":"0","type":"Entertainment","lang":"72.5644771","id":"4","title":"Team building ","isAttend":0,"app_id":"2","speaker_id":"1","lat":"23.0419169","floor_plan":"","handoutfile":"sc4.pdf"}],"19th Aug 2013":[{"agenda":"entertainment weekly events","endtime":"19th Aug 2013 16:00 pm","starttime":"19th Aug 2013 09:00 am","status":"1","location":"GMDC Ground Counter1,Ahmedabad","speaker":"Salim Kg","parent":"0","type":"Entertainment","lang":"72.5669487","id":"5","title":"Ceritification course","isAttend":1,"app_id":"2","speaker_id":"1","lat":"23.0400935","floor_plan":"","handoutfile":""}],"21st Aug 2013":[{"agenda":"entertainment weekly events","endtime":"21st Aug 2013 16:00 pm","starttime":"21st Aug 2013 09:00 am","status":"1","location":"GMDC Ground Counter2,Ahmedabad","speaker":"chirag ch","parent":"0","type":"Entertainment","lang":"72.5644771","id":"6","title":"Networking Breakfast","isAttend":0,"app_id":"2","speaker_id":"2","lat":"23.0419169","floor_plan":"","handoutfile":""}]};

私のコードですが、成功しません

var keyArr =[];
    for (var key in jsonObj) {
        keyArr.push(key);

    }
    var i =0;
    for(i=0;i<keyArr.length; i++){
        //console.log(jsonObj[keyArr[i]]);
        //console.log("main obj=="+jsonObj[keyArr[0]]);
        keyArr.i =[];
        for(x in jsonObj[keyArr[i]]){
            keyArr.i.push({
                lbl1:jsonObj[keyArr[i]][x]['title'],
                lbl2:jsonObj[keyArr[i]][x]['agenda'],
                template:"hboxEventSection"
            });
        }

    }
    console.log(keyArr);

助けてください

前もって感謝します。

4

1 に答える 1

0

これを行う組み込みの手段はありません。PHP の JSON 関数は、転送または保存のために可能な限りデータを圧縮するように設計されています。人間が読める形式ではないため、不要な空白は削除されます。

独自のコードを記述して、配列をループし、例から手動で形式を生成する必要があります。

于 2013-08-17T08:05:36.150 に答える