Как я могу сохранить данные вопроса для использования в моем приложении? - PullRequest
1 голос
/ 07 июня 2019

Мне нужно хранить данные вопроса в виде cms, например wordpress, и использовать конечную точку 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 вставляет разрывы строк и параграфы:

<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

Как я могу использовать такие данные в хранилище более доступным способом?

1 Ответ

0 голосов
/ 07 июня 2019

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);
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...