jqgrid:从json数据中获取返回值

时间:2010-10-21 10:56:21

标签: php javascript

如何从json字符串中获取返回值?

例如,在下面的代码中,我如何解析和读取变量searchxx

来自PHP:

$responce->page = $page; 
$responce->total = $total_pages; 
$responce->records = $BC->tot_count; 
**$responce->searchxx = $sSchWhere;
$responce->order = $sOrder;**

while ($data) ......

echo json_encode($responce);

来自HTML(Firebug):

"page":"1","total":2,"records":"26",**"searchxx":"T0.NAME=pluto"** ,"order":"T0.NAME desc","rows":[{"id":"63025c7a-12ad-102c-bd62-005056801340","account_id":"c30c7934-e0f3-102b-8fd4-005056801340","actions":"","edtNAME":"Rossi Mario","edtACCOUNT_NAME":"<a href=\#\">Rossi Mario<\/a>","edtAREA":"DEMO","edtSTATUS":"Aperta","edtPRIORITY" ......etc.

我有这段代码:

jQuery("#list2").navGrid('#pager2'{edit:false,add:false,del:false,search:false,refresh:false})
       .navButtonAdd('#pager2',{   
       caption:"View Condition Where",    
       buttonicon:"ui-icon",    
       onClickButton: function(){

           alert($("#list2").getGridParam('searchxx')); **//Should output NULL**
           },     position:"last" });

如何从jsondata获取返回值searchxx

2 个答案:

答案 0 :(得分:1)

使用json_decode()

将JSON字符串转换为数组

示例:

$array = json_decode($your_json_string);
echo $array['searchxx']; // Should output "T0.NAME=pluto"

答案 1 :(得分:0)

我认为http://www.json.org/js.html应该有所帮助。如果没有,请查看图书馆jQueryMooTols等等。