如何将数组对象转换为数组字符串

时间:2016-12-09 03:35:10

标签: php jquery arrays json object

我有一个像这样的结果控制台:

[Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object, Object]

我想这样结果

[{value: '1', text: 'one'}, {value: '2', text: 'two'}]

this is full of code

3 个答案:

答案 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>