JSON.stringify(),
将value(Object,Array,String,Number...)序列化为JSON字符串

JSON.parse(), 将JSON数据解析为js原生值

toJSON(), 作为JSON.stringify中第二个参数(函数过滤器)补充

我们都会使用jQuery的ajax方法取得json数据但是我们有的时候也要使用json数据给PHP传值,这个怎么做哪?

首先去http://code.google.com/p/jquery-json/  下载一个jquery.json-2.Xxxx.min.js 包

二、在javascript中建立 数据格式

function ChannelDataType(){

this.typeid;

this.choice;

}

三、给这个数据格式赋值,这里采用二维数组,这样例显得比较复杂一些

for(i=0;i<arr_channel.length;i++){

if(arr_channel[i][2]>1){

var cdt=new ChannelDataType();

cdt.typeid=arr_channel[i][0];

cdt.choice=arr_channel[i][2];

arr[j]=cdt;

j=j+1;

}

}

四、压缩成json数组

var jdata=$.toJSON(arr);

五、ajax传值,在调试阶段把dataType : "text",由于是ajax,所以在php那边没法看到结果,只能通过传回echo信息来调,所以要dataType : "text",等调完了再变为dataType : "json",或者其他的。

六、PHP程序

$arrChannel = json_decode($_POST['json'],true);

//echo count($arrChannel);

foreach($arrChannel as $arr)

echo( $arr['typeid']);

随机推荐

  1. 安装spy-debugger查看前端日志

    有时需要查看前端页面日志,但是前端同学有时忘记开启vConsole.为了调试方便,最好在本地可以查看前端日志,做到一劳永逸. 1.安装node 网上搜教程 2.安装spy-debugger sudo ...

  2. 廖雪峰Java4反射与泛型-3范型-6super通配符

    1.super通配符 1.1super通配符第一种用法 泛型的继承关系 Pair<Integer>不是Pair<Number>的子类,如 static void set(Pai ...

  3. HDOJ 2001 ASCII码排序

    #include<set> #include<iostream> using namespace std; int main() { char a, b, c; while ( ...

  4. Find the peace with yourself

    The purpose of being mature is to find the real calm and peace with yourself. Or you can say the tur ...

  5. (转)Linux 系统服务的启动顺序解析 rc.*

    介绍系统按照不同级别启动时需要启动的服务. 进入目录:etc 执行命令:ls -l | grep "rc.*" | sort 结果如下图:   1 系统在启动时,通过inittab ...

  6. 高通平台读写nv总结

    一,引言      1. 什么是NV       高通平台的NV,保存了系统运行过程中各个模块可能用到的一些参数值,它是以单个文件的形式保存在EFS中,但用户是不能随意访问的,只能通过QXDM来进行读 ...

  7. nginx 端口转发配置

    nginx.conf #user nobody; worker_processes ; #error_log logs/error.log; #error_log logs/error.log not ...

  8. Spring MVC post请求乱码解决

    在页面发送POST请求,将中文传递给controller,在编译平台发生乱码,导致存储到数据库中的数据也乱码 解决办法: 在web.xml中添加一个编码过滤器 <filter> <f ...

  9. pthread mutex

    pthead_mutex_t mutex; 1:create: pthread_mutex_init(pthread_mutex_t* mutex, const pthread_mutexattr_t ...

  10. go 数据类型type尝试

    package main import "fmt" import "encoding/json" type Human struct{ Name string ...