Selvakumar Mohan Selvakumar Mohan - 1 year ago 94
JSON Question

The JSON output does not contain a key: "value"

I have a

JSON
parsing issue with my Swift code below. The error I am getting says that my
JSON
output does not contain a key
value
.

My code:

Alamofire.request(url, method: .get, headers: headers).responseJSON { (response) -> Void in

let jsonValue = response.result.value as! NSDictionary
if let bpArray = jsonValue["value"] as? [NSDictionary]{
for results in bpArray {...}


Issue:
This conversion doesnt work:
if let bpArray = jsonValue["value"] as? [NSDictionary]


My JSON Structure:

{
d: {
results: [
{
__metadata: {},
Key: "AFBWhULFHtKU4j4FhWCmKg==",
ParentKey: "AAAAAAAAAAAAAAAAAAAAAA==",
RootKey: "AFBWhULFHtKU4j4FhWCmKg==",
Partner: "MM-CARR-01",
Type: "2",
Description: "MM Demo Carrier Created for Single Stop / MA",
FrieghtOrder: {}
},
...

Answer Source

Assuming you want to access the results key so try like this:-

if let bpArray = jsonValue["results"] as? [String: AnyObject]{
//yourcode
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download