Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I turn this unicode into a dict?
    primarykey
    data
    text
    <p>Sorry, I completely neglected to mention that I'm using Python. Let me try this again.</p> <p>I'm using Python to consume a web service that returns the following JSON:</p> <pre><code>{ "results" : [ { "paramName" : "output", "dataType" : "GPString", "value" : "{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}" } ], "messages" : [ ] } </code></pre> <p>Here are the important snippets from my fetching/parsing code:</p> <pre><code>import urllib import httplib2 import json import simplejson http = httplib2.Http() headers, response = http.request(url, 'GET') if headers['status'] == "200": responseAsJson = simplejson.loads(response) print "response = " + repr(responseAsJson) results = responseAsJson['results'][0]['value'] </code></pre> <p>Unfortunately, this leaves me with the following value for <em>results</em> (as reported in PyScripter Debugger's Variables window):</p> <pre><code>u"{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}" </code></pre> <p>I don't know how to then access the <em>address</em> or <em>city</em> keys, for instance.</p> <p>Can you tell what I'm doing wrong, and how to fix it?</p> <p>Thanks, Jamie</p> <hr> <p><strong>Old version of my question (obsolete):</strong></p> <p>Here's the JSON I'm parsing:</p> <pre><code>response = {u'messages': [], u'results': [{u'dataType': u'GPString', u'value': u"{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}", u'paramName': u'output'}]} </code></pre> <p>I've drilled down to this node, and its type is "unicode." How do I make a dict out of this? I think the fact that it's unicode is preventing me from creating the dict or accessing its keys, but I'm not sure.</p> <pre><code>u"{'city': 'Falls Church', 'isRuralArea': False, 'zip': '22046', 'isNotInBTOPLMArea': True, 'longitude': '-77.186180', 'isGeocodable': True, 'county': u'Falls Church', 'isNotInBIPLMArea': True, 'state': 'VA', 'isLatLongInUSBounds': True, 'address': '604 Jackson St', 'latitude': '38.884937'}" </code></pre> <p>Thanks, Jamie</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload