JSON.parse:unexpected end of data at line 1 column 1 of the json data

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JSON.parse:unexpected end of data at line 1 column 1 of the json data相关的知识,希望对你有一定的参考价值。

SyntaxError: JSON.parse:unexpected end of data at line 1 column 1 of the json data
貌似是这个问题导致我的请求不能有响应,该怎么解决
我用JQUERY是这么请求数据的~~~

$(document).ready(function()
$("div#googlemap").click(function()
$.getJSON("https://maps.googleapis.com/maps/api/place/nearbysearch/json?key=AIzaSyAXZ9V6fIGp18M3FUgdpKiAHOpWDxLQ6BU&location=31.11,111.29&radius=5500&types=food&sensor=false",function(result)
alert("lalala");
);
);

是因为你用ajax访问的时候跨域了,在你服务端加上跨域头就可以解决这个问题! 参考技术A 貌似是说你的json格式不对哈。是不是你的json格式的数据的最后一条多加了一个逗号呢追问

没有的呢~~这个就是谷歌给的JSON数据呢

追答

让我看下你的json数据格式哈。

python helloworld_end_to_end

%%time

from pyspark.sql import SparkSession # Novo no PySpark 2.0
from pyspark.sql.types import StructType\
                            , StructField\
                            , IntegerType\
                            , StringType\
                            , DoubleType\
                            , DateType\
                            , TimestampType\
                            , BooleanType # Avaliar e inferir schemas
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline


# NomeCampo, TipoDados, Nullable
df_schema=StructType([
   StructField('ip', IntegerType(),True),
   StructField('app', IntegerType(),True),
   StructField('device', IntegerType(),True),
   StructField('os', IntegerType(),True),
   StructField('channel', IntegerType(),True),
   StructField('click_time',TimestampType(),True),
   StructField('attributed_time', DateType(),True),
   StructField('is_attributed', IntegerType(),True)
])

# ler os dados mas com schema definido - Improvements de velocidade muito grandes
df=spark.read.csv('./datasets/train_sample.csv',header=True,schema=df_schema)

from pyspark.sql.functions import year, month, dayofmonth

df=df.withColumn("click_time_date", df["click_time"].cast(DateType()))
df=df.withColumn("click_time_year", year(df['click_time_date']))
df=df.withColumn("click_time_month", month(df['click_time_date']))
df=df.withColumn("click_time_dayofmonth", dayofmonth(df['click_time_date'])) 
count=df.filter("is_attributed == 0").groupBy('click_time_dayofmonth').count().collect()

x=[str(c['click_time_dayofmonth']) for c in count]
y=[c['count'] for c in count]

import matplotlib.pyplot as plt

plt.bar(x,y)
plt.show()

以上是关于JSON.parse:unexpected end of data at line 1 column 1 of the json data的主要内容,如果未能解决你的问题,请参考以下文章

SyntaxError: "JSON.parse: unexpected non-whitespace ..." 当从 PHP 返回 JSON

解析 json 错误:SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

如何解决 SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data in ajax and p

jQuery解析JSON出现SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data(示例代码

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

笨方法学python--打印