0

如何在 PHP 中解析下面的 json 请求以提取特定值(在 value 中),如下所示:studentName、studentemail 和 courseName?每个请求只有一个条目,我不需要其余的值。我需要将这些存储为要写入 MYSQL 的 PHP 变量。解析是我遇到麻烦的地方

见下面的 json

     {"count":7,"data":[{"name":"Timestamp","ordinal":0,"value":"3/5/2013 2:45:31 PM"},{"name":"studentName","ordinal":1,"value":"mikejones"},{"name":"studentEmail","ordinal":2,"value":"mikejones%40gmail.com"},{"name":"courseName","ordinal":3,"value":"Grade%20Test"},{"name":"cpQuizInfoPassFail","ordinal":4,"value":"Fail"},{"name":"cpInfoPercentage","ordinal":5,"value":"75"},{"name":"institutionCode","ordinal":6,"value":"1212"}]}{"count":0}{"subject":"Course Transcript","footer":"Thank you for your participation!","footerURL":"https://sites.google.com/site/test393223837/googleformsdemotranscript/footerLogo.jpg","correctURL":"http//abc.com,"enabled":true,"correctResponseText":"Correct Response","showCorrectAnswers":true,"description":"Please keep this for your records as proof of course completion and certification.","incorrectURL":"https://sites.google.com/site/test3232393837/_/rsrc/1342229575450/googleformsdemotranscript/redX.png","fromName":"The Training Team","replyTo":"","headerURL":"https://sites.google.com/site/test3938232337/googleformsdemotranscript/CaptivateDev.jpg","isHTML":true,"title":"Course Transcript","to":"joe@gmail.com","userResponseText":"Your Response"}
4

2 回答 2

0

您可以使用 json_decode 函数,将 json 代码解析为 php 对象和数组。有关更多信息,请参阅文档。

于 2013-03-05T20:49:27.090 回答
0

一个问题是您的 json 无效。检查:

http://jsonlint.com/
http://jsonformatter.curiousconcept.com/

于 2013-03-05T20:51:08.890 回答