2017-02-16 91 views
-2

「成功」:1,「數據」:{「狀態」:「發送的消息」, 「message_id」:3594, 「personaluid」:「161」, 「gid」:「0」, 「uid」:「160」, 「message」:「cxzczxczxsada123」, 「chat_image」:「」, 「created_at」:「2017-02-04 16:52: 11" , 「UTYPE」: 「1」 } } {
APS = {警報= {體= hdhd; title =來自某人的姓名;}; badge = 1; };
「gcm.message_id」=「0:1487247942837269%19aca14d19aca14d」; 「gcm.notification.Content_available」= 1; 「gcm.notification.created_at」=「2017-02-16 17:55:41」;
「gcm.notification.uid」= 161; }我想將fcm響應與另一個響應結合起來

+0

應該是什麼結果呢? – RomanPerekhrest

+0

use array_merge – Sona

+0

如果您顯示用於獲取這2個響應的代碼,那麼也許我們可以提供幫助。 – RiggsFolly

回答

0

將您的json數據轉換爲php數組,然後使用array_merge將兩者合併。然後再將其轉換爲json數據。例如:

<?php 
    $json1='{"success":1, 
    "Data":{"status":"message sent","message_id":3594,"personaluid":"161","gid":"0","uid":"160","message":"cxzczxczxsada123","chat_image":"","created_at":"2017-02-04 16:52:11","utype":"1"} 
}'; 
$json2='{ 
    "multicast_id":5114850183838817498, 
    "success":1, 
    "failure":0, 
    "canonical_ids":0, 
    "results":[{"message_id":"0:1487247086404626%19aca14d19aca14d"}] 
}'; 

$ar1=json_decode($json1,true); 
$ar2=json_decode($json2,true); 
$ar1=array_merge($ar1,$ar2); 
echo json_encode($ar1); 

輸出:

{"success":1,"Data":{"status":"message sent","message_id":3594,"personaluid":"161","gid":"0","uid":"160","message":"cxzczxczxsada123","chat_image":"","created_at":"2017-02-04 16:52:11","utype":"1"},"multicast_id":5.1148501838388e+18,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1487247086404626%19aca14d19aca14d"}]} 
0

你可以數組合並2個解碼數組。

$data = json_decode($result, true); 
$data = array_merge($data[0], $data[1]); 
$data = json_encode($data, JSON_FORCE_OBJECTS);` 
相關問題