私はphp関数からcurl
を使用してサードパーティのAPIを呼び出しています。私はJSON形式(データ型は文字列)の応答を得ています。その応答をオブジェクトまたは配列に変換したい。私はを試しましたが、私はnull
を得ています。ブラウザでレスポンスを表示し、その文字列レスポンスをPHP変数に貼り付けてコピーすると、値が得られます。だから私は問題が何かを把握することはできません。ここでJSONオブジェクトに文字列レスポンスを変換するには?
は私のコードです:
{"identifier":"id", "items":[{"apiResult":"INVALID", "apiResultMessage":"Invalid controls. the field 'resource' is mandatory the field 'type of item' is mandatory the field 'element id' is mandatory the field 'resource' is mandatory", "id":"", "idProject":"", "nameProject":"", "refType":"", "refId":"", "idResource":"", "nameResource":"", "idRole":"", "nameRole":"", "comment":"", "assignedWork":"", "realWork":"", "leftWork":"", "plannedWork":"", "rate":"", "realStartDate":"", "realEndDate":"", "plannedStartDate":"", "plannedEndDate":"", "dailyCost":"", "newDailyCost":"", "assignedCost":"", "realCost":"", "leftCost":"", "plannedCost":"", "idle":"", "billedWork":""}] }
私も取得するために第二のparam "連想" を追加してみこの
$curl_response = str_replace("'", "\'", $curl_response);
$curl_response = json_decode($curl_response);
JSON文字列が有効なようで、http://json-parser.com/a7826645 'json_last_error_msg()'を使用してJSONデコードのエラーメッセージを確認しようとしています –
質問の一部をランダムに太字で表記しないでください。 –
@Anant、私は問題の答えを示しました。 –