help parsing json with php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I could use a bit of help parsing json (from riddle.com) with php.

the php result page shows:


<?php
$riddledata = date('Y-m-d H:i:s') . ' ' . print_r($_REQUEST, true) . "\n";

file_put_contents('webhook-logs.log', $riddledata, FILE_APPEND);

?>

and the $_REQUEST data looks like:

{"riddleId":179849,"data":{"riddle":{"id":179849,"title":"test1","type":"quiz"},"lead2":{" Name":{"value":"ddddd","type":"text"},"Email":{"value":"b@xxxxx","type":"email"}},"answers":[{"question":"<p>q1<\/p>","answer":"a1","correct":true,"quest ionId":1,"answerId":1}],"result":1,"resultData":{"scoreNumber":1,"resultIndex":1,"scorePer centage":100,"scoreText":"Your score: 1\/1","resultId":2},"embed":{"parentLocation":"https:\/\/www.riddle.com\/showcase\/179849 \/quiz"}}}

 

or maybe this after print_r($_REQUEST, true) ???

 

(

    [data] => {"riddleId":179849,"data":{"riddle":{"id":179849,"title":"test1","type":"quiz"},"lead2":{ "Name":{"value":"aaaaaa","type":"text"},"Email":{"value":"b@xxxxx","type":"email"}},"answers":[{"question":"<p>q1<\/p>","answer":"a1","correct":true,"quest ionId":1,"answerId":1}],"result":1,"resultData":{"scoreNumber":1,"resultIndex":1,"scorePer centage":100,"scoreText":"Your score: 1\/1","resultId":2},"embed":{"parentLocation":"https:\/\/www.riddle.com\/showcase\/179849 \/quiz"}}}

)


--- I tried parsing like:

$form_data = json_decode($_REQUEST);

$riddleId = $form_data->riddleId[0];

 --- also

$name = ' lead2 name '.$_REQUEST['data']['lead2']['Name']['value'];

 but nothing is working yet.


Q: What's the best way to parse this out and get the varied fields showing with php?

--
Thanks,
Dave - DealTek
dealtek@xxxxxxxxx
[db-19]





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux