本文将带您了解关于PHPcurl获取的json数据返回为空的新内容,同时我们还将为您解释phpcurljson的相关知识,另外,我们还将为您提供关于api-php中url接收的json数据,json_
本文将带您了解关于PHP curl获取的json数据返回为空的新内容,同时我们还将为您解释php curl json的相关知识,另外,我们还将为您提供关于api-php中url接收的json数据,json_decode为空、c# – WCF Json数据返回、java访问url获取json数据、json数据解析返回为空,哪里出有关问题了的实用信息。
本文目录一览:- PHP curl获取的json数据返回为空(php curl json)
- api-php中url接收的json数据,json_decode为空
- c# – WCF Json数据返回
- java访问url获取json数据
- json数据解析返回为空,哪里出有关问题了
PHP curl获取的json数据返回为空(php curl json)
请高手帮看看这是怎么回事 <?php header("Content-type:text/html;charset=utf-8"); header(''Content-type: application/json''); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://www.kuitao8.com/api/joke"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($ch); //接收返回信息 curl_close($ch); echo $result; ?>
api-php中url接收的json数据,json_decode为空
phpapijson手机服务器与客户端通信
#php后台json数据decode为结果空#
我使用手机传输数据到php后台,json_decode的结果为空。
手机传输的方式为post/get,编码格式为utf-8。
json数据为(包括代码中的单引号,我用字符串传输,json数据中必须为双引号):
''{"agent":"30","job":"1133","students":[{"working_hours_unit":"null","working_hours":"6","student_id":"191","commission_unit":"null","wage":"58","commission":"348","wage_unit":"null"}]}''
php代码获取到了以上json数据,并且能够使用echo输出。php代码:
$str=$_GET(''my_str''); echo $str;
输出测试结果然后我接着decode接收到的json数据,代码:
$form = json_decode($Noel,true); var_dump($form);
但很意外输出为**null** ,然后我用_echo json_last_error();_输出json转换错误,结果为4===json语法错误。
附上完整代码和截图:
$str=$_GET(''my_str''); echo $str;$form = json_decode($str,true); var_dump($form); echo json_last_error();
但是,当我把接收到的json单独接到PHP代码中,然后decode却能够正确解析。(我内心是崩溃的 〒_〒)
代码:`
立即学习“PHP免费学习笔记(深入)”;
$orm=''{"agent":"30","job":"1133","students":[{"working_hours_unit":"null","working_hours":"6","student_id":"191","commission_unit":"null","wage":"58","commission":"348","wage_unit":"null"}]}''; $arr=json_decode($form,true); var_dump($arr);
截图:
c# – WCF Json数据返回
//下面是我的一个类函数列表,即用户,我有10-15个类函数
public IEnumerable<Entity.User> User() { OpenStoredPorcedure("spDB"); DataSet d = ExecuteDataSet(); DataTable myDataTable = d.Tables[0]; var stList = new List<Entity.User>(); foreach (DaTarow dr in myDataTable.Rows) { Entity.User usr = new Entity.User() { FirstName = dr["first_name"].ToString() ?? null,LastName = dr["last_name"].ToString() ?? null }; stList.Add(usr); } return stList.AsEnumerable(); }
现在在WCF我想要一个像下面这样的功能
public IEnumerable fetchData(int id) { IEnumerable result1 = null; switch (id) { case 1: IEnumerable<Entity.User> result = User().AsEnumerable<Entity.User>().ToArray(); result1 = result; break; case 2: IEnumerable<Entity.Project> result = User().AsEnumerable<Entity.Project>().ToArray(); result1 = result; break; } return result1; }
但是我在使用上述方法时遇到此错误
请求错误
服务器遇到处理请求的错误.异常消息是’无法序列化类型的参数’System.Collections.Generic.List`1 [Entity User]'(对于操作’fetchData’,合同’isyncService’),因为它不是确切的类型’System.Collections.IEnumerable ‘在方法签名中并且不在已知类型集合中.要序列化参数,请使用类型将类型添加到已知类型集合中
现在我希望在WCF中我们调用这个函数并传递id,它将导致该实体类的json列表.
当我使用以下功能时,我正在获取Json数据
public List<Entity.User> fetchData() { return User().ToList(); }
解决方法
像这样的东西
[KNownType(typeof(YourDerivedType))]
这是一些帮助:http://blogs.msdn.com/b/sowmy/archive/2006/06/06/all-about-knowntypes.aspx
在你返回一个彼此不相关的类型的情况下,你应该按照OsQu的建议做一些事情.
java访问url获取json数据
最近在做接口,做自己的,也要把别人的接口封装到自己的接口里,比如直接访问url就能获取json数据的一种接口调用方式(我自己的也是这样对外提供的,感觉比较懒省事) 。
不仅自己封装别人的需要先读取到数据,在自己对外提供接口时,也需要提供示例模板,以下直接上代码:
public String loadJson (String url) {
StringBuilder json = new StringBuilder();
try {
URL urlObject = new URL(url);
URLConnection uc = urlObject.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(),"utf-8"));
String inputLine = null;
while ( (inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return json.toString();
}
中间的utf-8最好加上,能有效地预防中文乱码的出现。
json数据解析返回为空,哪里出有关问题了
json数据解析返回为空,哪里出问题了?
事情是这样的:
A网站提供一个连接接口,我验证登录信息通过后,返回一个json数据;但是我用$response = json_decode($output);却得不到数据、返回是空; 请教坛子里高手,怎么才能正确解析json数据成数组呢 、
数据部分截取:
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> {"total":359,"data":[{"Id":113023,"ProductId":2905,"ProductCode":"SZX01","ProductName":"计算机图书系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":new Date(1350691200000),"Deleted":0},{"Id":113024,"TourId":2905,"ProductCode":"SZX01","ProductName":"儿童图书教系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":new Date(1350777600000),"Deleted":0}]}
我的代码是这样的:
- PHP code
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?php header ("Content-Type:text/html; charset=UTF-8"); $url = ''http://58.61.153.173/dataport/GetAllTourInfo.ashx''; $host=array(''user: admin'',''password: admin_123''); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch,CURLOPT_HTTPHEADER,$host); $output = curl_exec($ch); print $output; //数据能打印出来,如上面那数据 $response = json_decode($output);//加上后边这两句,也不报错、但是也没有数据打印出来 print $response;//加上后边这两句,也不报错、但是也没有数据打印出来 ?>
------解决方案--------------------
因为
"StartDate":new Date(1350691200000),
造成的,把它从字符串中都拿掉就可以了.你试试,我刚才调试过试验了.
------解决方案--------------------
- PHP code
$s=''{"total":359,"data":[{"Id":113023,"ProductId":2905,"ProductCode":"SZX01","ProductName":"计算机图书系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":new Date(1350691200000),"Deleted":0},{"Id":113024,"TourId":2905,"ProductCode":"SZX01","ProductName":"儿童图书教系列","ProcessDays":1,"ProcessResume":"","WorkDayPrice":79.0000,"WeekdayPrice":89.0000,"NormalPrice":0.0000,"Catalog":"0","Type":0,"RDCatalog":0,"BizCatalog":0,"StartDate":new Date(1350777600000),"Deleted":0}]}''; $s=preg_replace(''/new Date[^,]+/'',''"$0"'',$s); print_r(json_decode($s)); /* stdClass Object ( [total] => 359 [data] => Array ( [0] => stdClass Object ( [Id] => 113023 [ProductId] => 2905 [ProductCode] => SZX01 [ProductName] => 计算机图书系列 [ProcessDays] => 1 [ProcessResume] => [WorkDayPrice] => 79 [WeekdayPrice] => 89 [NormalPrice] => 0 [Catalog] => 0 [Type] => 0 [RDCatalog] => 0 [BizCatalog] => 0 [StartDate] => new Date(1350691200000) [Deleted] => 0 ) [1] => stdClass Object ( [Id] => 113024 [TourId] => 2905 [ProductCode] => SZX01 [ProductName] => 儿童图书教系列 [ProcessDays] => 1 [ProcessResume] => [WorkDayPrice] => 79 [WeekdayPrice] => 89 [NormalPrice] => 0 [Catalog] => 0 [Type] => 0 [RDCatalog] => 0 [BizCatalog] => 0 [StartDate] => new Date(1350777600000) [Deleted] => 0 ) ) ) */ <div></div>
关于PHP curl获取的json数据返回为空和php curl json的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于api-php中url接收的json数据,json_decode为空、c# – WCF Json数据返回、java访问url获取json数据、json数据解析返回为空,哪里出有关问题了的相关信息,请在本站寻找。
本文标签: