0
を使用している情報を解析していないので、このjsonファイルをダウンロードしています。私はそれをテストし、ストリング1はうまく動作します。しかし、今はJSONオプションを使ってファイルを解析し、クラス内の変数に変換しようとしています。私はパーサ関数のすべてを正しく設定し、ダウンロード機能はうまく動作すると思います。だから問題は、私がta json型に応答を変更しようとしているときだと思う。私はその部分を正しくやっているのか分かりません。 これは私がこれまで持っているものです。SwiftyJsonを使用しているJSONパーサーは、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)
}
ここでJSONはその構文解析されるファイルです、それが働いて得た
{
"id" : 220,
"name" : "King Gus",
"total_points_earned" : null,
"points_available_to_spend" : null,
"rank" : null,
"order_history" : [ ],
"barcode_id" : "C-00000220"
}
この