简体   繁体   中英

Deserialize Object in String to Python Dict

So I'm using apache solr and python, when I send data in the form a dict/obj it is stored and received as

{
  "array": [
    "{key: value}, {key: value}, {key: value}",
    "{key: value}, {key: value}, {key: value}",
    "{key: value}, {key: value}, {key: value}"
  ],
}

is it possible to convert that python string into a python dict

NB the values I'm expecting are either string or float

Update: I decided to use the built-in JSON encoder to serialize each instance of a nested python dictionary and send that to the SOLR instance, finally when I'm retreving the data I just deserialize the already encoded json string

I decided to use the built-in JSON encoder to serialize each instance of a nested python dictionary and send that to the SOLR instance, finally when I'm retreving the data I just deserialize the already encoded json string

import json

{
  "array": [
    json.loads({key: value, key: value, key: value}),
  ],
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM