Well, this is my JSON string:
[{"id":1,"name":"firstname lastname","longitude":"45.567856","latitude":"345.2334"},
{"id":2,"name":"firstname1 lastname1","longitude":"45.567856","latitude":"345.2334"}]
This is my code where I'd like to split it:
api = 'http://localhost:8080/serviceBackend/employees'
json_data = requests.get(api).json()
print(json_data)
employeeName = json_data['']['name']
print(employeeName)
If I run this code I'm getting this error TypeError: list indices must be integers or slices, not str
The result should be
firstname lastname, firstname1 lastname1
json_data['']['name'], what do you expectjson_data['']to mean? What should the result be, and why? The error message saysTypeError: list indices must be integers or slices, not str. Did you try to understand that? Do you know what aTypeErroris? Do you know what alistis, and what anindexis? Can you think of a reason why the error might be complaining about alist index? Do you expect''to be a validlist index?foreach of the items that isinthe list that you get from the JSON? Maybe you should have something in your code that reflects that? Hint, hint.