2012-07-20 102 views
-1

我有这样的JSON:(这是为树视图jquery插件通过AJAX其中负载树形视图)转换PHP数组到JSON树状

[ 
{ 
    "text": "1. Pre Lunch (120 min)", 
    "expanded": true, 
    "classes": "important", 
    "children": 
    [ 
     { 
      "text": "1.1 The State of the Powerdome (30 min)" 
     }, 
     { 
      "text": "1.2 The Future of jQuery (30 min)" 
     }, 
     { 
      "text": "1.2 jQuery UI - A step to richnessy (60 min)" 
     } 
    ] 
}, 
{ 
    "text": "2. Lunch (60 min)" 
}, 
{ 
    "text": "3. After Lunch (120+ min)", 
    "children": 
    [ 
     { 
      "text": "3.1 jQuery Calendar Success Story (20 min)" 
     }, 
     { 
      "text": "3.2 jQuery and Ruby Web Frameworks (20 min)" 
     }, 
     { 
      "text": "3.3 Hey, I Can Do That! (20 min)" 
     }, 
     { 
      "text": "3.4 Taconite and Form (20 min)" 
     }, 
     { 
      "text": "3.5 Server-side JavaScript with jQuery and AOLserver (20 min)" 
     }, 
     { 
      "text": "3.6 The Onion: How to add features without adding features (20 min)", 
      "id": "36", 
      "hasChildren": true 
     }, 
     { 
      "text": "3.7 Visualizations with JavaScript and Canvas (20 min)" 
     }, 
     { 
      "text": "3.8 ActiveDOM (20 min)" 
     }, 
     { 
      "text": "3.8 Growing jQuery (20 min)" 
     } 
    ] 
} 
] 

我想要写一个PHP数组返回像JSON这个。请帮帮我。

我尝试了几种方法来做到这一点,但我做不到。

+0

是您找到PHP正确的阵列结构的问题,或者如何在PHP数组转换为JSON结构? – deceze 2012-07-20 08:17:41

+0

在php中有相同的数据:http://codepad.org/MHFHwBTs – Yoshi 2012-07-20 08:17:43

回答

2

可以使用json_encode PHP函数

+0

嗨,谢谢。蝙蝠我想要写一个PHP数组,当用json_encode回显这个数组。这个json像我的问题中的json – mohsen 2012-07-20 13:19:20