2 回答

TA貢獻1842條經驗 獲得超13個贊
你有一個對象數組。您需要連接name和value屬性。
$array = json_decode($data);
foreach ($array as $el) {
echo "{$el->name}-{$el->value},";
}

TA貢獻1817條經驗 獲得超6個贊
var jsonFromServer = '[{"name":"Agnes ","amount":"40000"},{"name":"John","amount":"35000"},{"name":"Joyce","amount":"50000"},{"name":"Peter","value":"45000"}]';
var json = JSON.parse(jsonFromServer);
var arrResult = []; // if array
//var textResult = ''; // if string
if(json && json.length){
for(var j = 0, jLen = json.length; j < jLen; j++){
var obIn = Object.values(json[j]);
var map = obIn.map(function(el){
return el.trim();
});
var res = map.join('-');
arrResult.push(res);
//textResult += res;
};
};
console.log(arrResult); // if array
//console.log(textResult); // if string
控制臺結果 [“Agnes-40000”,“John-35000”,“Joyce-50000”,“Peter-45000”]
- 2 回答
- 0 關注
- 149 瀏覽
添加回答
舉報