I am trying to access an element of a python list, after I do a line by line JSON object parsing, I can't access the values.
For example:
data1 = [{u'time': 136.648, u'name': u'machine', u'value': 71.3}];
data1 = str(data1)[1:-1]
print data1
print data1 ['time']
Grabbing the 'time' value from data1 gives an error:
TypeError: string indices must be integers, not str
{u'name': u'machine', u'value': 71.3, u'time': 136.648}
Alternatively the following works correctly:
data2 = '{"time": 136.648, "name": "machine", "value":71.3}'
data2 = json.loads(data2)
print data2
print data2 ['time']
Output:
{u'name': u'machine', u'value': 71.3, u'time': 136.648}
136.648
Why does one work and the other not? Both data1 and data2 seem to be the same thing.
I want to parse this list such that I can access the data inside of it:
data = [{u'time': 136.648, u'name': u'machine', u'value': 71.3}, {u'time': 138.648, u'name': u'machine2', u'value': 71.56}];