Odata / Json parse
Hej Eksperter..Jeg har brug for, at få parset et response fra en odata database. Men jeg har lidt problemer med at finde ud af det.
Her er min kode:
import urllib2, base64,json, time, threading
username = 'XXXX'
password = 'XXXX'
request = urllib2.Request("http://api.remoni.eu/Public/CalculationResults?$filter=DeviceId%20eq%2033%20and%20ResultTypeId%20eq%2021&$top=1&$orderby=Timestamp%20desc")
base64string = base64.encodestring('%s:%s' % (username, password)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
result = urllib2.urlopen(request)
data = result.read()
data = json.loads(data.decode("utf8"))
content = data['value']['Value']
print content
Her er mit response:
{
"@odata.context": "http://api.remoni.eu/Public/$metadata#CalculationResults",
"value": [
{
"CalculationResultId": "8915c70b-1cd5-48c7-9b21-aed629593148",
"Timestamp": "2015-11-18T12:14:03.832Z",
"ResultTypeId": 21,
"Value": 161519.454025834,
"DeviceId": 33,
"JobDefinitionId": null,
"AccountId": 3,
"DeviceValueId": 39,
"Unit": null
}
]
}
Det eneste jeg har brug for, er at få value.Value ud i en variable, så jeg kan bruge den videre i programmet.