0

i am working with wit.ai when i request a query in wit i get a response in json format, i want to use the specific value of that responce.

my code

        r = requests.get('https://api.wit.ai/message?v=20160918&q=%s' % speech,
                         headers={"Authorization": wit_ai_token})
        print r.text
        json_resp = json.loads(r.text)
        entities = None
        intent = None
        if 'entities' in json_resp:
            entities = json_resp['entities']
            intent = json_resp['entities']['time']['value']

and the response i am getting is

{"_text":"is it too late today","entities":{"time":[{"confidence":0.95358332243418,"value":"time","type":"value"}],"datetime":[{"confidence":0.963925,"values":[{"value":"2018-04-01T00:00:00.000+05:30","grain":"day","type":"value"}],"value":"2018-04-01T00:00:00.000+05:30","grain":"day","type":"value"}]},"msg_id":"0elPrXq5NAeS4b6q5"}

i want to know the value if first element of "entities" like in this case "entity":{"time", i want time and store it in a variable

  • sorry for unclear question but each time my response will contain a different entities value, like for now its 'time', but it can also be 'weather', 'map' etc...i want to find that value – mrritunjay pathak Mar 31 '18 at 21:07

2 Answers2

0
r = requests.get('https://api.wit.ai/message?v=20160918&q=%s' % speech,
                         headers={"Authorization": wit_ai_token}).json()
our_timestamp = r['entities']['time'][0]['value']

Your question is a bit unclear, but that should give you what you're looking for.

hd1
  • 33,938
  • 5
  • 80
  • 91
0

You need to loop over your data:

for item in json_resp['entities']:
    # Print out the entiti
    print(item)
Malthe Have Musaeus
  • 357
  • 1
  • 4
  • 13