php - Selecting a property from JSON -


i have json similar one:

    {"request": {"target":"affiliate_offer","format":"json","service":"hasoffers","version":"2","networkid":"adattract","method":"getpayoutdetails","api_key":"bd2e82f029c50b582db85868b7c0b8ab99d095886ab079f87b464bb68486c891","offer_id":"9463"},"response":     {"status":1,"httpstatus":200,"data":{"offer_payout":     {"payout":"0.820"}},"errors":[],"errormessage":null}} 

and want select value of payout 0.820.

here try

<?php include 'db.php'; $result = mysql_query("select * ada  require_approval='0' order i2 asc limit 0,10") or die(mysql_error()); // keeps getting next row until there no more while ($row = mysql_fetch_array($result)) {   echo "<div>";   $r = $row['id'];   $ri = $row['i2'];   // $ri contains no. 1 2 3 4 5..//   $json = ''; } $mydata = json_decode($json, true); $data = $mydata["response"]["data"]; $pay = $data[$ri]["offer_payout"][payout]; echo "</div>"; mysql_query("insert thumb(img,id) values('$nth','$oid')"); echo $pay; //output of 0.8200 not work plz here need help// } ?> 

you can values json that:

// json $json = '{"request": {"target":"affiliate_offer","format":"json","service":"hasoffers","version":"2","networkid":"adattract","method":"getpayoutdetails","api_key":"bd2e82f029c50b582db85868b7c0b8ab99d095886ab079f87b464bb68486c891","offer_id":"9463"},"response": {"status":1,"httpstatus":200,"data":{"offer_payout": {"payout":"0.82000"}},"errors":[],"errormessage":null}}';  // json_decode() function second param true array format $json_decoded = json_decode($json,true);  echo $json_decoded['response']['data']['offer_payout']['payout']; //0.82000 

how can in code?

you need change these 2 lines in code:

$data = $mydata["response"]["data"]; $pay = $data["offer_payout"]['payout']; //0.82000 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -