JSON 데이터를 구문 분석하지 못했습니다.NSArray 및 NSDictionary를이 SQL 데이터와 함께 어떻게 사용할 수 있습니까?
형식 '__NSArrayI'(0x10f02fc08)을 'NSMutableArray'(0x10f02fcd0)로 변환 할 수 없습니다.
JSON 데이터 here 및 코드는 여기에 있습니다.
echo json_encode($resultArray);
그리고 여기에 내 시험 코드가 있습니다.
func parseJSON() {
var jsonResult: NSMutableArray = NSMutableArray()
do{
jsonResult = try JSONSerialization.jsonObject(with: self.data as Data, options:JSONSerialization.ReadingOptions.allowFragments) as! NSMutableArray
} catch let error as NSError {
print(error)
}
var jsonElement: NSDictionary = NSDictionary()
let locations: NSMutableArray = NSMutableArray()
for i in 1...jsonResult.count
{
jsonElement = jsonResult[i-1] as! NSDictionary
let location = LocationModel()
if let name = jsonElement["Name"] as? String,
let address = jsonElement["Address"] as? String,
let latitude = jsonElement["Latitude"] as? String,
let longitude = jsonElement["Longitude"] as? String
{
location.name = name
location.address = address
location.latitude = latitude
location.longitude = longitude
}
locations.add(location)
}
DispatchQueue.main.async(execute: {() -> Void in
self.delegate.itemsDownloaded(items: locations)
})
}
왜 Swift에서 NSDictionary, NSArray 등을 사용하고 있습니까? – Alexander
@Ali 안녕하세요. 죄송 합니다만 귀하의 질문은 아직 명확하지 않습니다. 검색 방법을 잘 모르는 경우 [내 JSON 답변] (http://stackoverflow.com/search?tab=votes&q=user%3a2227743%20json)을 검색하여 시작할 수 있다고 제안 할 수 있습니까? 상당히 많은 부분이 있습니다. 모든 관련 링크를 통해 문제를 해결할 수있는 충분한 자료를 얻을 수 있습니다. 또는 독서 후 문제를 더 잘 설명 할 수 있어야합니다. 행운을 빕니다! – Moritz
@ EricAya 5 분 같이 업데이트하자. – Ali