Test Mtruk response parse - PHP Online
Form of PHP Sandbox
Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php
in the places where the PHP script should be executed.
Result of php executing
Full code of Test Mtruk response parse.php
- <?php
- $answer = '<?xml version="1.0" encoding="ASCII"?><QuestionFormAnswers xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionFormAnswers.xsd"><Answer><QuestionIdentifier>taskAnswers</QuestionIdentifier><FreeText>[{"explanation":"Very interesting image, depicting return from the Mars.","option1":{"imageB":false},"option2":{"imageA":true}}]</FreeText></Answer></QuestionFormAnswers>';
- $xml = simplexml_load_string($answer);
- $json = json_encode($xml);
- $array = json_decode($json, TRUE);
- // print_r($array);
- print_r($array['Answer'][1]['FreeText']);
- ?>