Heim  >  Artikel  >  Backend-Entwicklung  >  前端串js对象数组给php 所用框架thinkphp

前端串js对象数组给php 所用框架thinkphp

WBOY
WBOYOriginal
2016-06-23 13:39:58898Durchsuche

//js 对象<script>    person[]=new Object();    person[0].firstname="Bill";    person[0].lastname="Gates";     person[1].firstname="Bill";    person[1].lastname="Gates";    //将对象转为json字符串    var jsonstr=JSON.stringify(person);    //传递给php    $.post('url',{obj:jsonstr},function(data){},'json');</script>//php 代码public function get_json(){    //获取json字符串    //注意 用thinkphp 框架 最好不要用框架自带的I方法获取数据,因为I方法在过滤字符串的同时会把字符串内部的双引号转义,导致解析json失败 返回null.此时若用json_last_error()函数获取 介绍返回提示,返回值可能是4 表示语法错误。    $str=$_POST['obj'];    //解析json    $str=json_decode($str);}

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn