How can I access the values in this NSDictionary in Swift?

CaptainCOOLGUY

I am trying to access the 'address' object (String) in a dictionary:

Chain.sharedInstance().getAddress("19b7ZG3KVXSmAJDX2WXzXhWejs5WS412EZ"){  dictionary, error in
            NSLog("%@", dictionary)
            let value = dictionary["address"] as? String //returns nil
        }

this is the data I receive:

results =     (
            {
        address = 19b7ZG3KVXSmAJDX2WXzXhWejs5WS412EZ;
        confirmed =             {
            balance = 0;
            received = 20000000;
            sent = 20000000;
        };
        total =             {
            balance = 0;
            received = 20000000;
            sent = 20000000;
        };
    }
); }

How do I access the values in this dictionary when I keep getting nil?

Jeremy Pope

To clarify, the data you are posting is not JSON, but rather looks like JSONP. You aren't showing any code deserializing the the object, so I assume Chain.sharedInstance().getAddress is handling that aspect. If this is an instance of the Bitcoin API, you might look at their documentation. If it is their API, the documentation says the return is

A dictionary with a single "results" key, whose value is a array containing a single Address Object as a dictionary.

If that is the case if would be

if let resultsArray = dictionary["results"] as NSArray {
    if let dict = results[0] as NSDictionary {
        //dict["address"] should have your address
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I access values of [UIApplicationOpenURLOptionsKey : Any] in Swift 4?

How can I access elements in a NSDictionary which has no key?

How can I alphabetically sort the values in my NSDictionary with an NSArray?

NSDictionary seems to have multiple values for one key, how do I access the individual values?

How do I get the values of this NSDictionary

How do I convert swift Dictionary to NSDictionary

How can I access values in this JSON?

How can I access particular column values?

How can I access the RGB values of a UIColor?

How I can access to these values in body question,

How can I store an NSDictionary in a String:String?

How can I have access to values in a table with values() or iteritems()

How to access indices of an NSDictionary, and convert that key’s value to an Int in Swift?

Can I serialize a RealmObject to JSON or to NSDictionary in Realm for Swift?

Access data in NSDictionary using Swift

How do I assign image and label values from NSDictionary?

how do I serialise NSDictionary from a Class - Swift implementation

How do I cast an NSDictionary to a swift dictionary if the NSDictionary has integers for keys

How can I convert this object to an array and access values by key in React?

How can I access values within Optional NSSingleObjectArrayI?

How can I get access to multiple values of nested JSON object?

C How can i access values in misaligned memory

How can I access the key of a map without knowing the type of the values?

How can I access CURRENT values of environment variables in Python

How can I access specific values of a lavaan model by code?

How, with Ruby, can I access and compare these nested array values?

How can I access the associated values of SwiftyDropbox errors?

How can I access values from a C union in Rust?

How can I access list values using DOM in javascript?