1
[{
  "_text" = "turn off the air con";
  confidence = "0.609";
  entities =     {
      "on_off" =         (
                    {
              value = off;
          }
      );
  };
  intent = "aircond_temperature";
}]

I have a json response named "outcomes", and I would like to extract the "off" value from "on_off".

So far what I've done is to get the first element from the response and then cast it to an NSDictionary which works fine, and then using object for key to get the values of each dictionary, and casting them to their respective types.

let firstOutcome:NSDictionary = outcomes.first as! NSDictionary
let intent:String = firstOutcome.objectForKey("intent") as! String
let entities:NSDictionary = firstOutcome.objectForKey("entities") as! NSDictionary

But when it comes to entities I have no idea what type should I cast "on_off" to. Any ideas?

1
  • please post working son atleast Commented Dec 3, 2015 at 8:56

3 Answers 3

1

your "on_off" key contain array of dictionaries, so you could try to access it by using this code.

let entities:NSDictionary = firstOutcome.objectForKey("entities") as! NSDictionary
let onOff = entities["on_off"] as! NSArray
let firstValue = onOff.firstObject as! NSDictionary
print(firstValue["value"])
Sign up to request clarification or add additional context in comments.

Comments

0

The brackets tell the whole story. { is an object or dictionary, ( is an array. So, entities is a dictionary containing an array of dictionaries, where the inner dictionary has string keys and values.

1 Comment

Got it! Thanks for the explanation
0

Try this code:

let entities = entities["on_off"]

for var entity in entities {
    print_r(entity["value"])
}

1 Comment

I did and I get ( { value = off; } )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.