首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP数据处理

PHP数据处理
EN

Stack Overflow用户
提问于 2016-11-30 09:16:36
回答 2查看 30关注 0票数 1

嗨,我有这个数据,我想要改变它中的一些东西,我想用PHP来改变它,问题是我不知道如何访问那些特定的数据,它存储在一个变量中,错误地发布了我下面的代码,我也标记了我想要更改的数据。

代码语言:javascript
复制
{
  "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"
  }
}

这是我的代码:

代码语言:javascript
复制
$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的代码:

代码语言:javascript
复制
$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变量,在提交到服务器之前,我需要将所有数据放在一起。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-30 09:29:42

试试这个..。

代码语言:javascript
复制
$arr = json_decode($json);
$arr->pathsGroups[0]->active = 'true';
票数 1
EN

Stack Overflow用户

发布于 2016-11-30 09:19:14

请使用json_decode(),如:

代码语言:javascript
复制
$arr = json_decode($json, true);   // 2 parameter is true so that it returns an array instead of object

它将将json数据转换为数组并相应地使用它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40884354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档