我尝试从另一台提供json格式的服务器中获取Json数据但是我得到了 JSON.parse:意外的非空格字符 错误如果我使用foreach循环差异日期。
public function getNumber() {
$begin2 = new DateTime(date("Y-m-d", strtotime("-5 day")));
$interval2 = new DateInterval('P1D');
$end2 = new DateTime(date("Y-m-d", strtotime("+1 day")));
$daterange2 = new DatePeriod($begin2, $interval2, $end2);
foreach (array_reverse(iterator_to_array($daterange2)) as $val) {
$url = "ThisIsALinkperiods.action?periods=".$val->format("Ymd1300");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: Json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$contents = curl_exec($ch);
echo $contents;
}
}
这是我的错误的原因
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 4240 of the JSON data
回复后这是我的数据
[{"betEndtime":null,"betStartime":"2014-01-19 13:00:00","createTime":"2015-12-04 13:00:11","id":100005521
,"lotteryOpenStatus":5,"lotteryOpenTime":"2015-12-04 13:00:00","lotteryType":11,"luckNumber":"40615"
,"luckNumberSource":"","operatorName":"auto_open_draw","operatorTeleno":"","orderId":"","periods":"201512041300"
,"prizeNumCode":0,"prizeNumLevel":1,"productId":11111,"productJson":
..........................................................................
:"DRAW4","luckDrawDiscount":1,"maxLuckNumLen":5,"maxMoney":2000000,"minLuckNumLen":5,"minMoney":100,"nextStartTime"
:"2015-11-29 13:00:00","nextStopTime":"2015-11-29 17:45:00","openDrawType":0,"periodUnit":1,"periodUnitNum"
:1,"price":40,"productCode":"DRAW4","productDesc":"Draw4","productEndTime":20990119163000,"productId"
:11114,"productType":11,"rate":0,"resTmplProductId":11114,"stopTime":900,"validPeriod":2},"productName"
:"DRAW4","publicTime":null,"rewardMultiple":0,"updateTime":"2015-11-29 13:11:46","winAmount":0}]