How to convert a json data key-value pair into a dictionary without quotation marks? json quotation marks

Source: Internet
Author: User

How to convert a json data key-value pair into a dictionary without quotation marks? json quotation marks

Zookeeper recently met a website, and the returned data is disgusting. It is very troublesome to use regular expressions or other methods to replace rules one by one. Directly Using json. loads will certainly report an error.
The data returned by zookeeper is as follows. It is disgusting. You can try it yourself!

{
   serverSeconds: 1515659363,
   last_time: 1515659104,
   path: [{title: "All", id: "89", cType: "col"}],
   count: 13924,
     offset_page: 0,
     offset_num: 0,
   list: [{channel: {title: "sports", id: "94", cType: "col", url: ""}, title: "Guan Xiaodao competes: South Korea's U23 fight against the Spanish undefeated", url : "http://sports.sina.com.cn/l/2018-01-11/doc-ifyqnick6934937.shtml",type: '1', pic: '', time: 1515659104},
     {channel: {title: "Society", id: "92", cType: "col", url: ""}, title: "Men's web chat" beauty "is trying to be an object but was deceived by the bartender for 4,000 yuan ", url:" http://news.sina.com.cn/s/wh/2018-01-11/doc-ifyqqieu5746315.shtml",type: '1', pic: '', time: 1515658966},
     {channel: {title: "Sports", id: "94", cType: "col", url: ""}, title: "Female doctor reports sexual harassment from Boeing: suspected to have caused pregnant students to be pregnant", url: "http : //sports.sina.com.cn/others/pingpang/2018-01-11/doc-ifyqnick6909050.shtml ", type: '2', pic: '', time: 1515658784}]
}

Zookeeper now introduces a python library named demjson and can be directly installed using pip. It seems that there is a loss in mac. Github address for this library: https://github.com/dmeranda/demjson
The following shows how to use

a = "" "{
  serverSeconds: 1515659363,
  last_time: 1515659104,
  path: [{title: "All", id: "89", cType: "col"}],
  count: 13924,
    offset_page: 0,
    offset_num: 0,
  list: [{channel: {title: "sports", id: "94", cType: "col", url: ""}, title: "Guan Xiaodao competes: South Korea's U23 fight against the Spanish undefeated", url : "http://sports.sina.com.cn/l/2018-01-11/doc-ifyqnick6934937.shtml",type: '1', pic: '', time: 1515659104},
    {channel: {title: "Society", id: "92", cType: "col", url: ""}, title: "Men's web chat" beauty "is trying to be an object but was deceived by the bartender for 4,000 yuan ", url:" http://news.sina.com.cn/s/wh/2018-01-11/doc-ifyqqieu5746315.shtml",type: '1', pic: '', time: 1515658966},
    {channel: {title: "Sports", id: "94", cType: "col", url: ""}, title: "Female doctor reports sexual harassment from Boeing: suspected to have caused pregnant students to be pregnant", url: "http : //sports.sina.com.cn/others/pingpang/2018-01-11/doc-ifyqnick6909050.shtml ", type: '2', pic: '', time: 1515658784}]
} "" "
import demjson

b = demjson.decode (a)
print (b)
# Print out is a dictionary
print (type (b)) 

Isn't zookeeper easy? You can use this library to solve similar problems.

Copyright Disclaimer: This article is an original article by the blogger. For more information, see the source. Http://blog.csdn.net/Crazy__Hope/article/details/79053443


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.