我需要将问题数据存储在wordpress
这样的cms中,并使用json
端点将其放入我的应用程序。像这样:
<question>
What event marked the start of World War II?
</question>
<correct_answer>
Invasion of Poland (1939)
</correct_answer>
<incorrect_answers>
["Invasion of Russia (1942)","Battle of Britain (1940)","Invasion of Normandy (1944)"]
</incorrect_answers>
问题是生成的json看起来像这样,wordpress
插入换行符和paragrpahs:
<p><question><br \/>\nWhat event marked the start of World War II?<br \/>\n<\/question><br \/>\n<correct_answer><br \/>\nInvasion of Poland (1939)<br \/>\n<\/correct_answer><br \/>\n<incorrect_answers><br \/>\n[“Invasion of Russia (1942)”,”Battle of Britain (1940)”,”Invasion of Normandy (1944)”]<br \/>\n<\/incorrect_answers><br \/>\n<question><br \/>\ntesting<br \/>\n<\/question><br \/>\n<correct_answer><br \/>\nyseesf<br \/>\n<\/correct_answer><br \/>\n<incorrect_answers><br \/>\n[“gffdg”,”fdgfdg”,”dfgfdgfd”]<br \/>\n<\/incorrect_answers><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What event marked the start of World War II? Invasion of Poland (1939) [“Invasion of Russia (1942)”,”Battle of Britain (1940)”,”Invasion of Normandy (1944)”] testing yseesf [“gffdg”,”fdgfdg”,”dfgfdgfd”]<\/p>\n
如何以一种更易于访问的方式使用这样的存储数据?
答案 0 :(得分:0)
PHP部分
$questions = array(
array(
'question' = 'What event marked the start of World War II?',
'answers' = array('Invasion of Russia (1942)', 'Invasion of Poland (1939)', 'Battle of Britain (1940', 'Invasion of Normandy (1944)'),
'correct_answer' = 1
),
array(
'question' = 'Question 2',
'answers' = array('A1', 'A2', 'A3', 'A4'),
'correct_answer' = 0
)
);
$json = json_encode($questions);
update_post_meta($post->ID, 'questions', $json);