我有以下JSON值:
[newcomposeMail={"msg":"test mail","senderUserId":"1006","subject":"test","to":"10002"}, composeMail]
我的问题是:
INSERT INTO `push_msg_table`(`pid`, `subject`, `msg`, `sentuserid`, `sent_time`, `upload_path`, `status`) VALUES()
我需要将这些值插入到mysql表中。我是JSON的新手。
尝试在php中使用
json_decode(newComposeemail,true);
添加true将获得正确的Array,否则它将在php中返回Object
如果json中有多个条目,则必须循环遍历json数组,以便在DB 中插入多个条目
首先确保通过请求数组或json_decode函数获取php中的所有json值。
然后,在您获得所有将以字符串形式出现的值之后,因此只有将整数字符串值转换为整数,INSERT查询才能工作。所以查询将是这样的。
INSERT INTO push_msg_table(pid, subject, msg, sentuserid, sent_time, upload_path, status) VALUES(integer,string,string,integer,string,string,integer);
希望这对你有帮助!!
尝试以下代码:
$newcomposeMail= '{"msg":"test mail","senderUserId":"1006","subject":"test","to":"10002"}';
$qryVal = json_decode($newcomposeMail,true);
//echo $qryVal->{'subject'};//here how you get json values
$qry ="INSERT INTO `push_msg_table`(`pid`, `subject`, `msg`, `sentuserid`, `sent_time`, `upload_path`, `status`) VALUES($pid,'".$qryVal->{'subject'}."','".$qryVal->{'msg'}."','".$qryVal->{'senderUserId'}."',.............";