大家好我是swift的新手,我正在从JSon解析数据并在tableview中显示它工作正常,在Json中有些字符串是阿拉伯语的。就像这样
[{"ID":"1","EmpName":"أحمد زكي","CustName":"Yasser","Status":"sold","Item_ID":"1","Date":"\/Date(1494147367000)\/"}]
当我解析这个Json的时候,就像这样 EmpName =“\ U0623 \ U062d \ U0645 \ U062f \ U0632 \ U0643 \ U064a”;
这是我的解析代码
func jsonparse()
{
let url = URL(string: "http://mobile.net/orders?userid=1")
Alamofire.request(url!, method: .post, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON(completionHandler:
{
response in
print(response.result.value as Any)
let JsonData = response.result.value as! [[String:Any]]
for jsonvalues in JsonData
{
self.Trans_data.append(Trans_userInfo.init(CustName:(jsonvalues["CustName"] as! String) , Date:(jsonvalues["Date"] as! String) , EmpName: (jsonvalues["EmpName"] as! String), ID: jsonvalues["CustName"] as? Int , Item_ID: (jsonvalues["Item_ID"] as! String) , Status: jsonvalues["Status"] as? String ))
}
self.reload_Data()
}).resume()
}
如何以阿拉伯语显示EmpName
答案 0 :(得分:0)
您在控制台上看到的内容并不重要,它们的值为Encoded
,但当您在标签上显示时,它只会出现Arabic
。
也不要使用guard let / if let
guard let custName = jsonvalues["CustName"] as? String, let date = jsonvalues["Date"] as? String, let empName as? String, let custName = as? Int, let itemId = jsonvalues["Item_ID"] as? String, let status = jsonvalues["Status"] as? String else {
print("Problem in fetching values")
return
}
self.Trans_data.append(Trans_userInfo.init(CustName: custName , Date: date, EmpName: empName, ID: custName , Item_ID: itemId, Status: status ))