【问题标题】:JSON parse valueerror - Python [duplicate]JSON解析值错误 - Python [重复]
【发布时间】:2015-12-01 11:08:19
【问题描述】:

我正在尝试解析有效​​的 JSON 文件并遇到以下错误。我还验证了我的 JSON 结构。

错误:

  parseJSON = json.loads(jsonFilePath);
  File "C:\Python34\lib\json\__init__.py", line 318, in loads
    return _default_decoder.decode(s)
  File "C:\Python34\lib\json\decoder.py", line 343, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Python34\lib\json\decoder.py", line 361, in raw_decode
    raise ValueError(errmsg("Expecting value", s, err.value)) from None
ValueError: Expecting value: line 1 column 1 (char 0)

代码:

vendorID = input('ENTER the vendor ID :');
jsonFilePath="C:/Users/user/Desktop/maradata.json";
parseJSON = json.loads(jsonFilePath);

我还在这里粘贴了 JSON 数据: http://pastecode.org/index.php/view/23471909

谁能建议我在哪里遇到错误?

【问题讨论】:

  • json.loads() 采用 JSON 字符串,而不是文件名。看看骗子。

标签: python json


【解决方案1】:

加载stringjson有两种方法:

  1. json.loads(s) s 是字符串。
  2. json.load(fp) fp 是文件指针。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    相关资源
    最近更新 更多