, so dass ich diese JSON-Datei herunterladen und dieser Teil funktioniert. Ich habe es getestet und die Saite funktioniert einwandfrei. Aber jetzt versuche ich, die JSON-Option zu verwenden, um die Datei in Variable in der Klasse zu analysieren. Ich denke, ich habe alles richtig in der Parser-Funktion eingerichtet und die Download-Funktion funktioniert gut. Also ich denke, das Problem ist, wenn ich versuche, die Antwort in ta json Typ zu ändern. Ich weiß nicht, ob ich diesen Teil richtig mache. Das ist, was ich bisher habe:JSON-Parser mit SwiftyJson analysiert keine Informationen mit Alamofire
func downlaodPromoData(myUrl : String, myUser : String, myPass : String)
{
Alamofire.request(.GET, myUrl)
.authenticate(user: myUser, password: myPass)
.validate(statusCode: 200..<300)
.responseString { response in
//print("Success: \(response.result.isSuccess)")
//print("Response String: \(response.result.value)")
self.downloadJson = response.result.value!
//print("Calling parser")
//self.parsePromoJson(self.downloadJson)
}.responseJSON { response in
print("Response JSON: \(response.result.value)")
let swiftyJsonVar = JSON(response.result.value!)
self.parseCustomerInfo(swiftyJsonVar)
//let userJson = JSON() as! NSDictionary
//parseCustomerInfo(userJson)
}
}
/*
var barcodeNumber : String = ""
var customerName : String = ""
var totalPointsEarned : String = ""
var pointsEarned : String = ""
var rank : String = ""
*/
func parseCustomerInfo(json : JSON)
{
print("Starting parsing")
for result in json[""].arrayValue {
barcodeNumber = result["barcode_id"].stringValue
customerName = result["name"].stringValue
totalPointsEarned = result["total_points_earned"].stringValue
pointsEarned = result["points_available_to_spend"].stringValue
rank = result["rank"].stringValue
}
customerName = "Gus"
print("new Customer name" + customerName)
print("Updateing ui")
let myData : String = "UserName: " + customerName + "\n" + "Total Points: " + totalPointsEarned + "\n" + "Ava Apoints: " + pointsEarned + "\n" + "Rank: " + rank
uiResultsTextField.text.appendContentsOf(myData)
}
Hier wird die Json seiner Parsen
{
"id" : 220,
"name" : "King Gus",
"total_points_earned" : null,
"points_available_to_spend" : null,
"rank" : null,
"order_history" : [ ],
"barcode_id" : "C-00000220"
}
mit dieser