0

我正在使用活动监视器的 api并尝试以json它应该执行的格式检索响应。我回应了回应,这是一个例子:

string(342) "HTTP/1.1 400 Bad Request
Server: csw
Cache-Control: private, s-maxage=0
X-CS-Node: 25
Content-Type: application/json; charset=utf-8
P3P: CP="OTI DSP COR CUR IVD CONi OTPi OUR IND UNI STA PRE"
Date: Sun, 27 Jan 2013 12:35:10 GMT
Connection: close
Content-Length: 66


{"Code":250,"Message":"List title must be unique within a client"}"

我想得到唯一的最后一行。我怎样才能做到这一点 ?(我试图用空白来爆炸响应,但它没有改变任何东西)。

编辑:文档在这里,我调用一个方法method(),返回响应$response = method()并运行echo($response)

4

2 回答 2

0

您可以使用 preg_match 函数通过搜索正则表达式“/{.*}/”来搜索 JSON。

preg_match('/\{.*\}/', $response, $matches);
于 2013-01-27T12:58:54.290 回答
0

基于此示例代码,您应该执行以下操作:

$result = method(); # I'm assuming you over-simplified the code in your question and "method" isn't the real method name
echo $result->response; # Not echo $result;
于 2013-01-27T13:01:53.340 回答