简体   繁体   English

如何正确解析API响应

[英]How to parse API response correctly

My Problem is relatively simple: 我的问题相对简单:

I make an API call and get the following answer in response: 我进行API调用并得到以下答案:

[{"RowKey":24764}] 

The Content-Type I'm receiving is text/html 我收到的Content-Type是text/html

Somehow, I'm just not able to parse this correctly. 不知何故,我只是无法正确解析这个问题。 neither json_encode or json_decode seems to help. json_encodejson_decode似乎都没有帮助。

I'm trying to Map the object into my response class: 我正在尝试将对象映射到我的响应类:

class ApiResponse {

  public $schedules = [];

}

with the json object mapper from: https://github.com/mintware-de/json-object-mapper 使用json对象映射器: https//github.com/mintware-de/json-object-mapper

Consider this test case: 考虑这个测试用例:

$response = '[{"RowKey":24764}]';
$result = json_decode($response, true);
echo $result[0]['RowKey']; // Output: 24764

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM