我有一个结果控制台是这样的:如何变换数组对象到数组字符串
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
我想造成这样
[{value: '1', text: 'one'}, {value: '2', text: 'two'}]
我有一个结果控制台是这样的:如何变换数组对象到数组字符串
[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]
我想造成这样
[{value: '1', text: 'one'}, {value: '2', text: 'two'}]
像这样:
$array = json_decode(json_encode($nested_object), true);
或只是键入丢:
$array = (array) $yourObject;
如果你想通过循环来做到这一点,我认为你可以使用这个
$array = array();
$counter = 0;
foreach(Object as $val)
{
$array[$counter]['value'] = $val->value;
$array[$counter]['text'] = $val->text;
$counter++;
}
你的代码是为我的php文件? – gierg
使用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>
[这是我的完整代码](https://jsfiddle.net/oyocxdz4/1/) – gierg
\ *什么都有你试过了吗? –
[请参阅此代码](https://jsfiddle.net/oyocxdz4/) – gierg