dongliang1893 2016-08-05 06:59
浏览 137
已采纳

使用REST GET进行JSON响应 - PHP

I am using cURL and REST to access a database and a query search, i am getting the following response when i use echo $response:

HTTP/1.1 200 OK Date: Fri, 05 Aug 2016 06:53:02 GMT Server: Apache Content-Language: en-US RNT-Time: D=58292 t=1470379982660626 RNT-Machine: 128.65 Transfer-Encoding: chunked Content-Type: application/json { "items": [ { "tableName": "Country", "count": 1, "columnNames": [ "id" ], "rows": [ [ "12" ] ] } ], "links": [ { "rel": "self", "href": "https://test.cust.com/services/rest/connect/v1.3/queryResults?query=select%20ID%20from%20CO.Country%20where%20CO.Country.Country=%27USA%27" }, { "rel": "canonical", "href": "https://test.cust.com/services/rest/connect/v1.3/queryResults" }, { "rel": "describedby", "href": "https://test.cust.com/services/rest/connect/v1.3/metadata-catalog/queryResults", "mediaType": "application/schema+json" } ] } 

i tried to use JSON_decode() but so far i got nowhere, how can i get my parameters here ? to be more specific, the "id" value.

  • 写回答

5条回答 默认 最新

  • duanhuangyun3887 2016-08-05 08:01
    关注

    If I get you right you have 2 options:

    • turn off receiving headers curl_setopt($ch, CURLOPT_HEADER, 0)
    • break your response by , you'll get header and body
    list($header, $body) = explode("
    
    ", $response, 2)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算