如何将json对象内嵌到php中的字符串? [英] How do I implode a json object to a string in php?
本文介绍了如何将json对象内嵌到php中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将这个json保留在要转换为字符串的变量中吗?
I have this json held in a variable that I am trying to convert to a string?
$json_object = '[{"125":"1"},{"126":"2"},{"127":"3"},{"128":"4"},{"129":"5"},{"130":"6"},{"131":"7"},{"132":"8"},{"133":"9"},{"134":"10"},{"135":"11"}]';
我想要的最终结果是这样的东西:
What I want as my end result is something that looks like this:
$json_object1 = '1,2,3,4,5,6,7,8,9,10,11';
$json_object2 = '125,126,127,128,129,130,131,132,133,134,135';
有没有一种方法可以修改implode(",",$json_object)
函数来实现这一目标?
Is there a way we can modify the implode(",",$json_object)
function to achieve this?
另一个问题: 任何想法我们怎么可能把它
Another question: Any idea how we might put this
{"26":"Child - 1500.00","28":"Foreigner - 4000.00","27":"Resident - 3000.00"}
到类似列表
26 : Child - 1500.00
27: Resident - 3000.00
28: Foreigner - 4000.00
推荐答案
$json_object = '[{"125":"1"},{"126":"2"},{"127":"3"},{"128":"4"},{"129":"5"},{"130":"6"},{"131":"7"},{"132":"8"},{"133":"9"},{"134":"10"},{"135":"11"}]';
$json = json_decode($json_object);
echo implode(", ", array_map(function($obj) { foreach ($obj as $p => $v) { return $p;} }, $json));
echo "<br>";
echo implode(", ", array_map(function($obj) { foreach ($obj as $p => $v) { return $v;} }, $json));
这篇关于如何将json对象内嵌到php中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文