将JSON字符串转换为变量以回显出来 [英] Convert JSON String into variables to echo out

查看:145
本文介绍了将JSON字符串转换为变量以回显出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下JSON字符串:

  [{\index\:0,\date \:20120030 \,\title \:\afsa\}] 

我需要把内容转换成一个变量foreach。



到目前为止, / p>

  $ json_data_string = $ _POST ['hidden_​​event']; //然后清理
$ array_data = json_decode($ json_data_string);

echo $ json_data_string;

我需要能够回显每一个。例如:

  foreach {
echo $ date;
echo $ title;





感谢您的帮助。
<解决方案我认为如果你想使用这个使用jQuery,你会这样做: - $ / $>

  var recordList = [{\index\:0,\date \:\20120030\,\title\:\afsa \}] 

jQuery.each(recordList,function()
{
alert(this.Name); //例如
alert(this。日期); //例如
});

或者像这样: - $ /

<$ p $ $ .ajax({
type:POST,
url:URL,
cache:false,
data:values,
dataType:'json',
success:function(json)
{
var date = json.date;
alert(date);
} // end成功函数
});


I have the following JSON string:

[{\"index\":0,\"date\":\" 20120030\",\"title\":\"afsa\"}]

And I need to get out the contents into a variable foreach one.

This is how it is picked up so far...

 $json_data_string = $_POST['hidden_event']; // sanitize however
 $array_data = json_decode($json_data_string);

 echo $json_data_string;

I need to be able to echo each out. for example:

 foreach {
   echo $date;
   echo $title;
 }

Thanks in advance for any help.

解决方案

I think if you want to use this using jquery you will do like this:-

var recordList = [{\"index\":0,\"date\":\" 20120030\",\"title\":\"afsa\"}]

jQuery.each(recordList, function()
{
    alert(this.Name); // For example
    alert(this.date); // For example
});

or like this:-

      $.ajax({
                          type: "POST",
                          url: URL,
                          cache:false,
                          data: values,
                          dataType:'json',
                          success: function(json)
           {
                                var date = json.date;
                                alert(date);
                                }       // end success function
                        });  

这篇关于将JSON字符串转换为变量以回显出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆