2017-02-25 2 views
0

다음과 같은 JSON 파일이 있습니다. 구문 분석하고 내 tableview를 채우고 싶습니다.swift - JSON 사전 구문 분석

은 내가 얻고 싶은 것은 "자료", "카테고리", "product_types"

["facets": { 
     "material" : { 
     "data" : [ 
      { 
      "count" : 3, 
      "value" : "95% Polyester, 5% Spandex" 
      }, 
      { 
      "count" : 1, 
      "value" : "%100 Modal" 
      } 
     ], 
     }, 
     "categories" : { 
     "data" : [ 
      { 
      "id" : "7", 
      "name" : "test" 
      } 
     ], 
     }, 
     "product_types" : { 
     "data" : [ 
      { 
      "count" : 3, 
      "value" : "Sweatshirt" 
      }, 
      { 
      "count" : 1, 
      "value" : "Babet" 
      }, 
     ], 
     } 
    }] 

내 코드입니다 :

var list: [String:JSON]? = [:] 
func loadList(){ 
ModafiliAPI.sharedInstance.refine(callback: { (refineList) in 
      if let data = refineList["facets"].dictionaryValue as [String:JSON]?{ 
       self.list = data 
       self.RefineTableView!.reloadData() 
       print(self.refineList!) 
      } 
     }) 
} 

내가으로부터 "면"에 접근 할 수있는 관찰 인쇄 출력. Ambiguous reference to member 'subscript'

있는 UITableViewCell :

var refineList:[String:JSON]?{ 
     didSet{ 
      self.setupRefineList() 
     } 
    } 
+1

. * 실제 * 컬렉션 유형 또는 사용자 정의 클래스/구조체에 대해 JSON을 구문 분석하는 훌륭한 도구 일뿐입니다. 테이블 뷰 데이터 소스 및 대리자 메서드에서 개체를 deserialize하기 위해 많은 불필요한 오버 헤드를 생성합니다. 그리고 구체적인 기존 테이블 뷰의 데이터 소스 배열을 선택적으로 선언하지 마십시오. – vadian

답변

0

엑스 코드가 refineList 어떤 유형 모르고, 그것은 그를 위해 모호한

시도하지만 cellforrowat에

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "RefineCell") as! RefineTableViewCell 
     cell.refineList = self.refineList?[indexPath.row] //-->>error 
     return cell 
    } 

나는 다음과 같은 오류를 얻고있다

cell.refineList = self.refineList?[indexPath.row] as! [String:JSON] 

cell.refineList 유형을 확인할 수도 있습니다.

또한 시도 : 당신은 모델에 SwiftyJSON을 사용해서는 안

guard let list = refineList?[indexPath.row] else { 
     print ("Unexpected error !!") 
     return cell 
} 
cell.refineList:[String:JSON] = list as! [String:JSON] 
+0

셀 코드로 제 질문을 업데이트했습니다. 로 추가! [String : JSON] 동일한 오류가 발생합니다. –

+0

셀의 refineList 유형은 무엇입니까? UITableViewCell 코드를 보내 주시면 도움이 될 수 있습니다. – iLandes

+0

제 질문의 맨 아래 부분을 확인하십시오. –