Hi I am really new to JSON and Python, here is my dilemma, it's been bugging me for two days. Here is the sample json that I want to parse.
{
"Tag1":"{
"TagX": [
{
"TagA": "A",
"TagB": 1.6,
"TagC": 1.4,
"TagD": 3.5,
"TagE": "01",
"TagF": null
},
{
"TagA": "A",
"TagB": 1.6,
"TagC": 1.4,
"TagD": 3.5,
"TagE": "02",
"TagF": null
}
],
"date": "10.03.2017 21:00:00"
}"
}
Here is my python code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import urllib2
jaysonData = json.load(urllib2.urlopen('URL'))
print jaysonData["Tag1"]
How can I get values of TagB and TagC? When I try to access them with
jaysonData = json.load(urllib2.urlopen('URL'))
print jaysonData["Tag1"]["TagX"]["TagB"]
The output is:
TypeError: string indices must be integers
When I do this:
print jaysonData["Tag1"]
The output is:
{
"TagX": [
{
"TagA": "A",
"TagB": 1.6,
"TagC": 1.4,
"TagD": 3.5,
"TagE": "01",
"TagF": null
},
{
"TagA": "A",
"TagB": 1.6,
"TagC": 1.4,
"TagD": 3.5,
"TagE": "02",
"TagF": null
}
],
"date": "10.03.2017 21:00:00"
}"
I need to reach TagX, TagD, TagE but the below code gives this error:
print jaysonData["Tag1"]["TagX"]
prints
print jaysonData["Tag1"]["TagX"]
TypeError: string indices must be integers
How can I access TagA to TagF with python? Thanks in advance.