Zyrd Jan Zyrd Jan - 2 days ago 6
JSON Question

PHP data handling

hi i have this data and i want to change something in it that i want to change using PHP the problem is i don't know how to access that specific data it is stored in a variable ill post my code below also i have labeled the data i want to change.

{
"id" : "",
"name" : "",
"namePostfix" : "",
"updatedTime" : "2016-11-29T16:35:31.189Z",
"createdTime" : "2016-11-07T05:19:20.352Z",
"clientId" : "",
"url" : "",
"impressionUrl" : "",
"trafficSource" : {
"id" : "",
"name" : "",
"postbackUrl" : null,
"pixelRedirectUrl" : null,
"type" : "CUSTOM",
"predefinedType" : null
},
"country" : {
"code" : "NZ",
"name" : "New Zealand"
},
"costModel" : "CPA",
"clickRedirectType" : "DOUBLE_HTML",
"paths" : [ {
"weight" : 100,
"active" : true,
"landers" : [ {
"lander" : {
"id" : "",
"namePostfix" : "",
"name" : ""
},
"weight" : 100
} ],
"offers" : [ {
"offer" : {
"id" : "",
"name" : "",
"namePostfix" : ""
},
"weight" : 100
} ]
} ],
"pathsGroups" : [ {
"condition" : {
"country" : {
"predicate" : "MUST_BE",
"countryCodes" : [ "NZ" ]
},
"customVariableConditions" : [ {
"predicate" : "MUST_NOT_BE",
"index" : 0,
"texts" : [ "[zone]", "Unknown", "unknown" ],
"text" : "[zone]"
}, null, {
"predicate" : "MUST_NOT_BE",
"index" : 2,
"texts" : [ "Unknown", "[clickid]", "unknown" ],
"text" : "Unknown"
}, null, null, null, null, null, null, null ]
},
"paths" : [ {
"weight" : 100,
"active" : true,
"landers" : [ {
"lander" : {
"id" : "",
"namePostfix" : "",
"name" : ""
},
"weight" : 100
}, {
"lander" : {
"id" : "",
"namePostfix" : "",
"name" : ""
},
"weight" : 100
} ],
"offers" : [ {
"offer" : {
"id" : "",
"name" : "",
"namePostfix" : ""
},
"weight" : 100
} ]
} ],
"active" : false //change this to true
} ],
"cpa" : 1.2,
"revenueModel" : "RPA_AUTO",
"redirectTarget" : "INLINE",
"inlineFlow" : {
"name" : "",
"countries" : [ {
"code" : "",
"name" : ""
} ],
"conditionalPathsGroups" : [ {
"conditions" : {
"country" : {
"predicate" : "MUST_BE",
"countries" : [ {
"code" : "",
"name" : ""
} ]
},
"customVariable" : {
"values" : [ {
"predicate" : "",
"variableIndex" : 1,
"variableValues" :
}, {
"predicate" : "MUST_NOT_BE",
"variableIndex" : 3,
"variableValues" :
} ]
}
},
"paths" : [ {
"name" : "Path 1",
"active" : true,
"weight" : 100,
"landers" : [ {
"weight" : 100,
"lander" : {
"id" : "",
"name" : "",
"numberOfOffers" : 1,
"url" : ""
}
}, {
"weight" : 100,
"lander" : {
"id" : "",
"name" : "",
"numberOfOffers" : 1,
"url" : ""
}
} ],
"offers" : [ {
"weight" : 100,
"offer" : {
"id" : "",
"name" : "",
"url" : "",
"affiliateNetwork" : {
"id" : ""
}
}
} ],
"offerRedirectMode" : "DOUBLE_HTML",
"realtimeRoutingApiState" : "DISABLED"
} ]
} ],
"defaultPaths" : [ {
"name" : "Path 1",
"active" : true,
"weight" : 100,
"landers" : [ {
"weight" : 100,
"lander" : {
"id" : "",
"name" : "",
"numberOfOffers" : 1,
"url" : ""
}
} ],
"offers" : [ {
"weight" : 100,
"offer" : {
"id" : "",
"name" : "",
"url" : "",
"affiliateNetwork" : {
"id" : ""
}
}
} ],
"offerRedirectMode" : "DOUBLE_HTML",
"realtimeRoutingApiState" : "DISABLED"
} ],
"defaultOfferRedirectMode" : "DOUBLE_HTML"
}
}


here is my code:

$wh = curl_init();

curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "GET");


$head = array();
$head[] = "Cwauth-Token: " . $tok;
curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

$resulta = curl_exec($wh);
if (curl_errno($wh)) {
echo 'Error:' . curl_error($wh);
}
echo "Request:" . "<br>";
echo '<pre>' . print_r($resulta, true) . '</pre>';
$resulta->pathGroups->active='true';


i really dont know if what iam doing is right. someone help me please
tried using json_decode
here is my code where i use json_decode:

$wh = curl_init();

curl_setopt($wh, CURLOPT_URL, "https://core.voluum.com/campaigns/" . $id);
curl_setopt($wh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($wh, CURLOPT_CUSTOMREQUEST, "GET");


$head = array();
$head[] = "Cwauth-Token: " . $tok;
curl_setopt($wh, CURLOPT_HTTPHEADER, $head);

$resulta = curl_exec($wh);
if (curl_errno($wh)) {
echo 'Error:' . curl_error($wh);
}
echo "Request:" . "<br>";
$campinfo = json_decode($resulta, true);
echo '<pre>' . print_r($campinfo, TRUE) . '</pre>';
foreach($campinfo['pathsGroups'] as $datacamp){
echo $datacamp['active']=1;


yes i have change the value with this code but my problem is how will i put the value back to the $resulta variable i need all the data in one piece before i can submit to server.

Answer

Try this...

$arr = json_decode($json);
$arr->pathsGroups[0]->active = 'true';
Comments