I am using python url library to get json response from spatial reference website.This is my code. I get response_read="u'{\'type\': \'EPSG\', \'properties\': {\'code\': 102646}}'" but i need this response in this form:"{'type': 'EPSG', 'properties': {'code': 102646}}". How i achieve output in this form?
headers = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request("http://spatialreference.org/ref/esri/"nad-1983-stateplane-california-vi-fips-0406-feet"/json/", None, headers)
response = urllib2.urlopen(req)
response_read = response.read().decode('utf-8')
result = json.dumps(response_read)
epsg_json = json.loads(result)
epsg_code = epsg_json['properties']['code']
return epsg_code
Use the String. replaceAll() method to remove all backslashes from a string, e.g. str. replaceAll('\\', '') . The replaceAll() method will remove all backslashes from the string by replacing them with empty strings.
Using replace() Function Along with The json. Loads() Function to Remove Backslash from Json String in Python.
String jsonFormattedString = jsonStr. replaceAll("\\", "");
you need to first use dumps then loads
json_data = json.dumps(response_read)
json_without_slash = json.loads(json_data)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With