简体   繁体   English

这是我作为 API 响应得到的什么类型的结果?

[英]What type of result is this which i am getting as API response?

This is my JSON这是我的 JSON

$result=[{CFirst: "test3"},{CLast: "test3"},{CEmail: "test2@gmail.com"}]

I am getting this as a result of an API request.由于 API 请求,我得到了这个。 I guessed it was json, so tried to json_decode() , but it didn't work and json_last_error() returned code 4.我猜是 json,所以尝试json_decode() ,但没有用, json_last_error()返回代码 4。

Thanks for help感谢帮助

Your JSON is in bad format , you need to enclose them under double quotes like this.您的 JSON 格式错误,您需要像这样将它们括在双引号中。

[{"CFirst": "test3"},{"CLast": "test3"},{"CEmail": "test2@gmail.com"}]

The CFirst,CLast & CEmail have been wrapped around double quotes for your information. CFirst,CLastCEmail已用双引号括起来供您参考。

The code..编码..

<?php
$json='[{"CFirst": "test3"},{"CLast": "test3"},{"CEmail": "test2@gmail.com"}]';
print_r(json_decode($json,true));

Demo演示

EDIT :

<?php
$result='[{CFirst: "test3"},{CLast: "test3"},{CEmail: "test2@gmail.com"}]';
$result=str_replace(array('{',':'),array('{"','":'),$result); //<--- Add this
print_r(json_decode($result,true));

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

相关问题 为什么有时我无法通过2captcha API得到响应? - Why am I sometimes not getting a response with 2captcha API? 我从用于 Stripe 事件的 webhook url 收到空白响应 - I am getting blank response from webhook url which I am using for Stripe events 通过数据库获取结果的问题,其中会话ID登录在用户ID中,我将不得不检查通过链接获取的uid - Issue with getting result by database where session id is logged in user id and I would have to check uid which i am getting by link 我需要调用一个可以在 windows 中运行但在 linux 中不能运行的 API,我收到 401 错误 - I need to call an API which is working in windows but not in linux, I am getting 401 error 我没有收到来自ajax请求的回复 - I am not getting response from ajax request 我的Ajax响应速度很慢 - i am getting ajax response slow 为什么我在ajax响应开始时得到?? - Why I am getting � at the start of ajax response? 我没有收到 flutter 的任何回复 - I am not getting any response with flutter 我没有通过 while 循环得到预期的结果 - I am not getting expected result with a while loop 当结果应该是数组时,为什么要得到字典? - Why am I getting a dictionary as a result when the result should be an array?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM