2017-03-07 12 views
0

페이지 매김을 지원하는 json URL이 있습니다. 내 질문에 어떻게 alamofire 및 swiftyjson 사용하여이 페이지 매김 페이지를 구문 분석 할 수 있습니다?alamofire와 swiftyjson을 신속하게 사용하여 페이지 매김 URL을 구문 분석하는 방법은 무엇입니까?

내 JSON URL이 같은 :

{ 
    "meta":{ 
     "code":200 
    }, 
    "data":{ }, 
    "pagination":{ 
     "total":86, 
     "totalPages":3, 
     "page":1, 
     "nextPage":2, 
     "nextPageUrl":"http://.............?page=2" 
    } 
} 

** !!!!!!! UPDATE !!!!!!! **

내 같은 코드 그러나 나는 몇 가지 예외를 얻을 :

func GetDataFromUrl(from:String){ 

     Alamofire.request(from, method: .get).validate().responseJSON { response in 
      switch response.result { 
      case .success(let value): 
       let json = JSON(value) 

       self.storeData = [PopulerMagazalarData]() 

         //...Creating Data Obj. 

         let data = PopulerMagazalarData() 

         let username = json["data"]["store"]["user"]["username"].string 
         let userpic = json["data"]["store"]["user"]["profilePicture"].string 
         let productsCount = json["data"]["store"]["productsCount"].int 
         let description = json["data"]["store"]["description"].string 
         let followedby = json["data"]["store"]["user"]["counts"]["followedBy"].int 
         let totalPage = json["pagination"]["totalPages"].int 
         let count:Int? = json["data"]["products"].array?.count 
         if let ct = count { 

          for index in 0...ct-1{ 

          let datas = PopulerMagazalarData() 

          let images = json["data"]["products"][index]["images"]["standart"]["url"].string 

          datas.img1 = images 
          self.storeData.append(datas) 
          } 
         } 


         //***************** 
         data.username = username 
         data.profilPic = userpic 
         data.producsCount = productsCount 
         data.desc = description 
         data.followedby = followedby 

         //****************** 
         self.storeData.append(data) 

       for index in 2 ... totalPage! { 

        self.GetDataFromUrl(from: "https://api......../store/\(username!)?page=\(index)") 
       } 

            // for refresh collecitonView 
        self.refresh_now() 



      case .failure(let error): 
       print(error) 
      } 
     } 
    } 

    //...CollectionView ReloadData func... 
    func refresh_now(){ 

     DispatchQueue.main.async (
      execute: 
      { 
       self.MyStoreCollectionView.reloadData() 
     } 
     ) 

    } 

을하지만 난 스크롤 할 때 내 응용 프로그램을 내려.

+0

Google은 먼저 쉽게 알게 될 것입니다. –

+0

그러면 페이지 매김의 목적은 무엇입니까? 세 번째 페이지를 얻으려면 이미 두 번째 페이지 URL을 눌러야합니다. –

답변

0
// make the request with Alamofire 
Alamofire.request("myUrl").response { response in 

    // to create the SwiftyJSON object 
    let json = JSON(data: response.data!) 

    // get the values from the json response 
    let code = json["meta"]["code"].int 
    let total = json["pagination"]["total"].int 

} 
+0

내 말은, 나는 데이터에서 이미지 URL을 가지고 있고, 모든 페이지 매김 페이지를 사용하여 데이터에서이 이미지를 파싱하고이 이미지를 내 배열에 추가하려고합니다. – SwiftyIso

+0

전체 집합에 대해 각'data' 노드를 파싱하고 싶습니까? 따라서 각 데이터 집합을 얻기 위해 마지막 단계에 도달 할 때까지'nextPageUrl'을 사용하고 싶습니까? – dstepan