2017-06-09 42 views
-1

的JSONArray我想分析该字符串一个JSONObject,它包含一个JSONObjects解析字符串一个JSONObject,它包含一个JSONObjects

Array 
(
[Assignments] => Array 
    (
     [0] => Array 
      (
       [ass_name] => Test123 
       [class_id] => 2 
       [date_assigned] => 2017-08-23 
       [done] => false 
       [due] => 2017-08-23 13:34:54 
       [id] => 10 
       [weight] => 65 
      ) 

    ) 

) 

的JSONArray我尝试使用

$json = json_decode($testing,true); 
echo $json; 

其中$测试是我的整个字符串,但$ json回声没有。

+0

你的字符串已经是你发布的数组对象,那显然'json_decode'不起作用。 – Nidhi

+0

那么..什么工作? –

+0

这不是json,是吗? –

回答

0

检查这个例子中,

echo =>输出由逗号分隔的一个或多个串

print_r =>接受不仅字符串而是其他类型,包括数组和对象,格式化它们是可读

$testing = array("Assignments"=>array("ass_name"=>"Test123","class_id"=>"2","date_assigned"=>"2017-08-23","done"=>"false","due"=>"2017-08-23 13:34:54","id"=>"10","weight"=>"65")); 

$json = json_encode($testing); //convert array to json 
echo $json; 

$json1 = json_decode($json,true); //convert json to array 
print_r($json1); 
+0

这有助于我理解我的问题。谢谢。 –

+0

很高兴为您提供帮助。别忘了向上投票。@ JavierSalas – Nidhi

+0

@Nidni我投了票,但这个帐户太新了,它显示。 –

0

不要将echo用于打印数组或目标CTS。

$testing = json_encode(
    array(
     'Assignments' => array(
      0 => array(
       'ass_name'  => 'Test123', 
       'class_id'  => 2, 
       'date_assigned' => '2017-08-23', 
       'done'   => false, 
       'due'   => '2017-08-23 13:34:54', 
       'id'   => 10, 
       'weight'  => 65, 
      ), 
     ), 
    ) 
); 

$json = json_decode($testing, true); 
echo $json; // prints "Array" 
print_r($json); // prints all items in array