问题描述:

一下字符串转换为json类型

{u'src': u'crawl', u'cid': u'Ctengbangguoji', u'datatype': u'ItemBase', u'timestamp': 1383644151594, u'iid': u'26286', u'crawldata': {u'star': 3, u'attr': {u'type': u'item'}, u'crt': 1383644151, u'url': u'http://www.feiren.com/hotel/hotel_26286.html', u'creation_time': 1383644151, u'md5': u'ec35f0cb9f2cfaa841a1562d662fc982'}, u'method': u'UpdateItem'}




解决方案:

使用exec 'json_msg=%s'%(line)把字符串转换为dict类型就可以用了


补充:

把其他类型转换为字符串

除了str(variable)之外

cid = "%s"%(json_msg["cid"])

相关文章:

  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
猜你喜欢
  • 2022-01-10
  • 2021-07-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
相关资源
相似解决方案