PHP数据处理
您好,我有这样的数据,我想改变什么事情,我想用PHP的问题改变是我不知道如何访问它存储在一个变量,具体数据生病后我的代码下面我也标记了我想改变的数据。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';
我真的不知道,如果是什么做的IAM是正确的。有人帮我请 使用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变量在我可以提交给服务器之前,我需要所有数据。
尝试......
$arr = json_decode($json);
$arr->pathsGroups[0]->active = 'true';
感谢您的答复生病试试这个 –
感谢它像一个魅力 –
不客气工作.... –
使用json_decode(),如:
$arr = json_decode($json, true); // 2 parameter is true so that it returns an array instead of object
将JSON数据转换成数组,并相应地使用它
你试过'json_decode( )'? – Raptor
给你什么错误?另外,去掉'true'附近的引号括号。 – KDOT
它不给任何错误,虐待更新我的职务,并添加在那里我使用json_decode一部分给我秒 –