第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

組合作為多個塊發(fā)送的大型 JSON

組合作為多個塊發(fā)送的大型 JSON

PHP
慕村225694 2021-12-03 16:20:42
我正在使用 cURL 和 PHP 來訪問 Salesforce API,并且其中大部分都在工作。當(dāng)您請求大量記錄時,Salesforce 會將數(shù)據(jù)分成 2000 塊。基本上,我有三個不同的大 JSON 塊和記錄數(shù)組,我想知道將它們組合成一個大對象的最佳方法是什么。當(dāng)有更多數(shù)據(jù)時,對象看起來像這樣。它為您提供了一個 nextRecordsUrl,您可以點擊它來獲取下一個塊:Array(    [totalSize] => 5000    [done] =>     [nextRecordsUrl] => /services/data/v20.0/query/somelongurlstring    [records] => Array        (            [0] => Array                (                    [attributes] => Array                        (                            [type] => Custom_Type__c                            [url] => sobjects/Custom_Type__c/thetypeid                        )                    [Requested_Prop__c] => someid                )            [1] => Array                ( [...]我的 curl 代碼似乎正在運行 - 基本上是這樣的:curl_setopt($ch2, CURLOPT_URL, "https://my.instance.salesforce.com/services/data/v20.0/query/?q=" . urlencode($_GET["q"]));curl_setopt($ch2, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer $token"));curl_setopt($ch2, CURLOPT_CUSTOMREQUEST, "GET");curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);curl_setopt($ch2, CURLOPT_FOLLOWLOCATION, 1);$isDone = false;while(!$isDone) {    $qresponse = curl_exec($ch2);    echo "<pre>";    $theJson = json_decode($qresponse, true);    echo print_r($theJson);    echo "</pre>";    $isDone = $theJson["done"] == true;    if(!$isDone)        curl_setopt($ch2, CURLOPT_URL, "https://my.instance.salesforce.com" . $theJson["nextRecordsUrl"]);}curl_close($ch2);問題是輸出實際上是多個json對象。我認為最簡單的方法可能是簡單地遍歷記錄并將它們附加到我在 PHP 中創(chuàng)建的某個 json 對象,但我擔(dān)心的只是如果這些獲取請求變得非常大可能需要的內(nèi)存量。有沒有“正確的方法”來做到這一點?
查看完整描述

1 回答

?
小唯快跑啊

TA貢獻1863條經(jīng)驗 獲得超2個贊

我最終只是自己附加數(shù)據(jù):


$isDone = false;

$finalJson = array();

while(!$isDone) {

    $qresponse = curl_exec($ch2);

    $theJson = json_decode($qresponse, true);

    $isDone = $theJson["done"] == true;

    foreach($theJson["records"] as $record) {  //Only return records

        $finalJson[] = $record;

    }

    if(!$isDone)

        curl_setopt($ch2, CURLOPT_URL, "https://my.instance.salesforce.com" . $theJson["nextRecordsUrl"]);

}

echo "<pre>" . json_encode($finalJson, JSON_PRETTY_PRINT) . "</pre>";


查看完整回答
反對 回復(fù) 2021-12-03
  • 1 回答
  • 0 關(guān)注
  • 160 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號