2013-07-05 172 views
0

我有存儲爲一個PHP變量「$ decoded_traces」 解碼的蹤跡JSON對象如下:如何添加到一個JSON對象

{ 
"Coords": [ 
    { 
     "Accuracy": "65", 
     "Latitude": "53.27771684322928", 
     "Longitude": "-9.01197836634846", 
     "Timestamp": "Fri Jul 05 2013 11:39:15 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.27771684322928", 
     "Longitude": "-9.01197836634846", 
     "Timestamp": "Fri Jul 05 2013 11:39:15 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.277716230919715", 
     "Longitude": "-9.01207806014157", 
     "Timestamp": "Fri Jul 05 2013 11:41:16 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.277716230919715", 
     "Longitude": "-9.01207806014157", 
     "Timestamp": "Fri Jul 05 2013 11:41:16 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.2776809358951", 
     "Longitude": "-9.012088286120322", 
     "Timestamp": "Fri Jul 05 2013 11:41:22 GMT+0100 (IST)" 


     } 
    ] 
} 

我需要在另一個名爲元/項/屬性添加'Image'就是二進制blob的文本。所以我需要的是:

{ 
"Coords": [ 
    { 
     "Accuracy": "65", 
     "Latitude": "53.27771684322928", 
     "Longitude": "-9.01197836634846", 
     "Timestamp": "Fri Jul 05 2013 11:39:15 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.27771684322928", 
     "Longitude": "-9.01197836634846", 
     "Timestamp": "Fri Jul 05 2013 11:39:15 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.277716230919715", 
     "Longitude": "-9.01207806014157", 
     "Timestamp": "Fri Jul 05 2013 11:41:16 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.277716230919715", 
     "Longitude": "-9.01207806014157", 
     "Timestamp": "Fri Jul 05 2013 11:41:16 GMT+0100 (IST)" 
    }, 
    { 
     "Accuracy": "65", 
     "Latitude": "53.2776809358951", 
     "Longitude": "-9.012088286120322", 
     "Timestamp": "Fri Jul 05 2013 11:41:22 GMT+0100 (IST)" 
    } 
], 
"Images": [ 
    { 
     "Image1": "binary", 
     "Image2": "binary2" 
    } 
] 
} 

我試過幾件事,但我真的有點迷路。顯然,添加後,我需要再次編碼,以便我可以回顯它。所有幫助讚賞

回答

0

一旦你解碼了JSON,它只是一個普通的PHP關聯數組。你添加到它就像你添加到任何其他陣列:

$decoded_traces['Images'] = $images; 
+0

你的意思是json_decode?此外,我已經有一個變量解碼:\t \t \t \t $ decoded_traces = json_decode($ traces,true); – user2363025

+0

如果它已經被解碼,你可以跳過這一步。 – Barmar

+0

所以你的問題只是「我如何添加到數組?」 'json_decode()'返回的數組沒有什麼特別之處。 – Barmar

相關問題