json

在进行json解码分钟海洋站数据发现有些不能解码,原来还以为是不是有些值为空就读不出来。

json_decode($str)返回NULL的一些原因:
1.$str只能UTF-8编码
2.元素最后不能有逗号(与php的array不同)
3.元素不能使用单引号
4.元素值中间不能有空格和n,必须替换

转换为utf8


$myfile = fopen($v, 'r') or die('Unable to open file!');
$line = trim(fgets($myfile));  //读取文件内容
$line = iconv("GBK", "UTF-8", $line); 


例如一下四个json文件,前面2个就解码失败


SELECT * FROM Station_Data_Minute WHERE COLLECTID = ''
=========================================
{"COLLECTID":"SQ201807240052.09713","NUMCODE":"09713","RESOURCENAME":"赤湾","DT":1532364720000,"WT":29.1,"SL":19.3,"WL":257,"AT":29.0,"BP":1000.6,"HU":81,"RN_1":0.3,"RN_2":99999.9,"WS_1":8.5,"WS_2":199,"WS_3":4.6,"WS_4":162,"WS_5":6.3,"WS_6":110,"WS_7":2230,"WS_8":9.0,"WS_9":150,"WS_10":0051}


SELECT * FROM Station_Data_Minute WHERE COLLECTID = ''
=========================================
{"COLLECTID":"SQ201807240051.09713","NUMCODE":"09713","RESOURCENAME":"赤湾","DT":1532364660000,"WT":29.1,"SL":19.3,"WL":258,"AT":29.1,"BP":1000.7,"HU":81,"RN_1":0.3,"RN_2":99999.9,"WS_1":6.2,"WS_2":192,"WS_3":4.4,"WS_4":160,"WS_5":6.3,"WS_6":110,"WS_7":2230,"WS_8":8.6,"WS_9":99,"WS_10":2222}
SQ201807240051.09713
09713
SELECT * FROM Station_Data_Minute WHERE COLLECTID = 'SQ201807240051.09713'
=========================================
{"COLLECTID":"SQ201807240050.09713","NUMCODE":"09713","RESOURCENAME":"赤湾","DT":1532364600000,"WT":29.1,"SL":19.3,"WL":257,"AT":29.1,"BP":1000.7,"HU":81,"RN_1":0.3,"RN_2":99999.9,"WS_1":4.5,"WS_2":206,"WS_3":4.2,"WS_4":157,"WS_5":6.3,"WS_6":110,"WS_7":2230,"WS_8":8.6,"WS_9":99,"WS_10":2222}
SQ201807240050.09713
09713
SELECT * FROM Station_Data_Minute WHERE COLLECTID = 'SQ201807240050.09713'
=========================================
{"COLLECTID":"SQ201807240049.09713","NUMCODE":"09713","RESOURCENAME":"赤湾","DT":1532364540000,"WT":29.1,"SL":19.3,"WL":257,"AT":29.1,"BP":1000.7,"HU":80,"RN_1":0.3,"RN_2":99999.9,"WS_1":4.5,"WS_2":166,"WS_3":4.3,"WS_4":157,"WS_5":6.3,"WS_6":110,"WS_7":2230,"WS_8":8.6,"WS_9":99,"WS_10":2222}
SQ201807240049.09713
09713


Last update: 2021-07-22|Pageview:296
Research Blog: EC | EC_INFO | EC_WORK |


BypResearch