简体   繁体   English

json.decoder.JSONDecodeError:期望值:第2行第1列(char 1)错误

[英]json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) error

        f = urlopen('http://api.wunderground.com/api/API_KEY_HERE/geolookup/conditions/q/CA/LosAngeles.json')
        str_response = f.readline().decode('utf-8')
        parsed_json = json.loads(str_response)
        location = parsed_json['location']['city']
        temp_f = parsed_json['current_observation']['temp_f']
        print ("Current temperature is:", temp_f, " degrees Fahrenheit")
        precep = parsed_json['current_observation']['precep_today_in']
        print("Current wind speed is:", precep)
        wind = parsed_json['current_observation']['wind_mph']
        print("Current wind speed is:", wind)
        gust = parsed_json['current_observation']['wind_gust_mph']
        print("Current wind gust speed:", gust)
        f.close()

I saw this JSONDecodeError: Expecting value: line 1 column 1 and I am unable to figure out how to add this piece of code in. 我看到了这个JSONDecodeError:期望值:第1行第1列 ,我无法弄清楚如何添加这段代码。

Here is the error: 这是错误: 在此输入图像描述

Here is my API part as requested: 这是我要求的API部分:

relative_humidity   "81%"
wind_string "Calm"
wind_dir    "NNE"
wind_degrees    23
wind_mph    0
wind_gust_mph   0
wind_kph    0
wind_gust_kph   0
pressure_mb "1012"
pressure_in "29.87"
pressure_trend  "-"
dewpoint_string "53 F (12 C)"
dewpoint_f  53
dewpoint_c  12
heat_index_string   "NA"
heat_index_f    "NA"
heat_index_c    "NA"
windchill_string    "NA"
windchill_f "NA"
windchill_c "NA"

With f.readline() , your code only reads the first line that the API returns, which happens to be a blank line, so the JSON encoder complains about no data. 使用f.readline() ,您的代码只读取API返回的第一行,这恰好是一个空行,因此JSON编码器抱怨没有数据。

Change f.readline().decode('utf-8') to f.read().decode('utf-8') , and you should get past this error. f.readline().decode('utf-8')改为f.read().decode('utf-8') ,你应该通过这个错误。

暂无
暂无

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

相关问题 错误:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - ERROR: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 奇怪的“json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)” - WEIRD "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ##json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)## - ##json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)## 什么是json.decoder.JSONDecodeError:期望值:第1行第1列(字符0) - What is json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 随机 json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - Random json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 遇到:json.decoder.JSONDecodeError:预期值:第1行第1列(字符0) - Encounter: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 奇怪:json.decoder.JSONDecodeError:预期值:第1行第1列(字符0) - weird: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)python - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) python json.decoder.JSONDecodeError:预期值:第2行第1列(字符2) - json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM