gpt4 book ai didi

php - 将 JSON 字符串解析为数据库

转载 作者:行者123 更新时间:2023-11-30 23:36:00 25 4
gpt4 key购买 nike

我在将 JSON 字符串解析到我的 MYSQL 数据库时遇到问题。这是发送到服务器的 JSON 字符串:

    [{"Description":"Detta är mitt quiz!","Title":"Mitt Quiz","Category":"Music","Language":"Swedish","Difficulty":1},{"QuestionNr1":{"WrongAnswer3":"Visby","WrongAnswer1":"Stockholm","RightAnswer":"Uppsala","WrongAnswer2":"Umeå","Question":"Vilken stad bor jag i?"},"QuestionNr2":{"WrongAnswer3":"Visby","WrongAnswer1":"Stockholm","RightAnswer":"Uppsala","WrongAnswer2":"Umeå","Question":"Vilken stad bor jag inte i?"}}]

这是调用[mArray JSonrepresentation]之前的数据;在上面

(
{
Category = Music;
Description = "Detta \U00e4r mitt quiz!";
Difficulty = 1;
Language = Swedish;
Title = "Mitt Quiz";
},
{
QuestionNr1 = {
Question = "Vilken stad bor jag i?";
RightAnswer = Uppsala;
WrongAnswer1 = Stockholm;
WrongAnswer2 = "Ume\U00e5";
WrongAnswer3 = Visby;
};
QuestionNr2 = {
Question = "Vilken stad bor jag inte i?";
RightAnswer = Uppsala;
WrongAnswer1 = Stockholm;
WrongAnswer2 = "Ume\U00e5";
WrongAnswer3 = Visby;
};
}

)

我正在使用 ASIHTTPRequest 的 POST 方法,但不知道如何在服务器端接收它并使用 PHP 将其解析到我的数据库。

谁能指出我正确的方向,我会很高兴!

//谢谢!

最佳答案

http://php.net/manual/en/function.json-decode.php

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json));

遍历 $json 并构建 sql 查询

关于php - 将 JSON 字符串解析为数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7319633/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com