嗨,我有这个数据,我想要改变它中的一些东西,我想用PHP来改变它,问题是我不知道如何访问那些特定的数据,它存储在一个变量中,错误地发布了我下面的代码,我也标记了我想要更改的数据。
{
"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"
}
}这是我的代码:
$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';我真的不知道我做的是不是对的。有人帮我--请尝试使用json_decode --这里是我使用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;是的,我用这段代码更改了值,但我的问题是如何将值返回到$resulta变量,在提交到服务器之前,我需要将所有数据放在一起。
发布于 2016-11-30 09:29:42
试试这个..。
$arr = json_decode($json);
$arr->pathsGroups[0]->active = 'true';发布于 2016-11-30 09:19:14
请使用json_decode(),如:
$arr = json_decode($json, true); // 2 parameter is true so that it returns an array instead of object它将将json数据转换为数组并相应地使用它。
https://stackoverflow.com/questions/40884354
复制相似问题