我有一个像这样的结果控制台:
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
我想这样结果
[{value: '1', text: 'one'}, {value: '2', text: 'two'}]
答案 0 :(得分:0)
像这样:
$array = json_decode(json_encode($nested_object), true);
或者只是强调它:
$array = (array) $yourObject;
答案 1 :(得分:0)
如果你想通过循环这样做我认为你可以使用这个
$array = array();
$counter = 0;
foreach(Object as $val)
{
$array[$counter]['value'] = $val->value;
$array[$counter]['text'] = $val->text;
$counter++;
}
答案 2 :(得分:0)
使用JSON.stringify()
var obj = [{value: '1', text: 'one'}, {value: '2', text: 'two'}]
console.log(JSON.stringify(obj));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>