when parsing json table view show repeat data [closed]Parsing JSON with Unix toolsHow to parse JSON in JavaWhy can't Python parse this JSON data?Parse JSON in JavaScript?How to parse JSON using Node.js?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How do I write JSON data to a file?Using Swift Collection Type to parse JSONParsing the JSON data with CodableUsing Codable to parse nested JSON data problem

How would one carboxylate CBG into it's acid form, CBGA?

Template code with 0xcccccccc in every ghidra decompiled function for some executables

In windows systems, is renaming files functionally similar to deleting them?

What does this Swiss black on yellow rectangular traffic sign with a symbol looking like a dart mean?

How is the idea of "girlfriend material" naturally expressed in Russian?

Basic power tool set for Home repair and simple projects

What is the highest power supply a Raspberry pi 3 B can handle without getting damaged?

Can the pre-order traversal of two different trees be the same even though they are different?

Synaptic Static - when to roll the d6?

How can the US president give an order to a civilian?

How to sort human readable size

Are there examples of rowers who also fought?

What is the name of the person who reconciled a line from Rudram to dakshinamurthy and Adi Shankaracharya?

How "fast" do astronomical events occur?

Why is Havana covered in 5-digit numbers in Our Man in Havana?

What jobs would people work in a frontier railroad town?

Why one uses 了 and the other one doesn’t?

Why things float in space, though there is always gravity of our star is present

Examples of protocols that are insecure when run concurrently

Is using legacy mode instead of UEFI mode a bad thing to do?

My student in one course asks for paid tutoring in another course. Appropriate?

Is there any way to revive my Sim?

Am I legally required to provide a (GPL licensed) source code even after a project is abandoned?

How could I create a situation in which a PC has to make a saving throw or be forced to pet a dog?



when parsing json table view show repeat data [closed]


Parsing JSON with Unix toolsHow to parse JSON in JavaWhy can't Python parse this JSON data?Parse JSON in JavaScript?How to parse JSON using Node.js?How do I POST JSON data with Curl from a terminal/commandline to Test Spring REST?How do I write JSON data to a file?Using Swift Collection Type to parse JSONParsing the JSON data with CodableUsing Codable to parse nested JSON data problem






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-3















When I'm parsing json array in a model and append data to show in tableview it repeat's data




class ProductsModel: Codable
let id, name: String

init(id: String, name: String)
self.id = id
self.name = name



if result == "Success"
if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
for filterArray in getArrayProducts
if let setFilterArray = filterArray as? [String: Any]
self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
self.localizationWork()
self.tblView.reloadData()
self.hideLoader();







self.arr repeat because of for loop but when I use self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]
all thing is correct but I want append data










share|improve this question















closed as off-topic by El Tomato, Cody Gray Mar 25 at 7:05


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – El Tomato, Cody Gray
If this question can be reworded to fit the rules in the help center, please edit the question.






















    -3















    When I'm parsing json array in a model and append data to show in tableview it repeat's data




    class ProductsModel: Codable
    let id, name: String

    init(id: String, name: String)
    self.id = id
    self.name = name



    if result == "Success"
    if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
    if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
    for filterArray in getArrayProducts
    if let setFilterArray = filterArray as? [String: Any]
    self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
    self.localizationWork()
    self.tblView.reloadData()
    self.hideLoader();







    self.arr repeat because of for loop but when I use self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]
    all thing is correct but I want append data










    share|improve this question















    closed as off-topic by El Tomato, Cody Gray Mar 25 at 7:05


    This question appears to be off-topic. The users who voted to close gave this specific reason:


    • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – El Tomato, Cody Gray
    If this question can be reworded to fit the rules in the help center, please edit the question.


















      -3












      -3








      -3








      When I'm parsing json array in a model and append data to show in tableview it repeat's data




      class ProductsModel: Codable
      let id, name: String

      init(id: String, name: String)
      self.id = id
      self.name = name



      if result == "Success"
      if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
      if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
      for filterArray in getArrayProducts
      if let setFilterArray = filterArray as? [String: Any]
      self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
      self.localizationWork()
      self.tblView.reloadData()
      self.hideLoader();







      self.arr repeat because of for loop but when I use self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]
      all thing is correct but I want append data










      share|improve this question
















      When I'm parsing json array in a model and append data to show in tableview it repeat's data




      class ProductsModel: Codable
      let id, name: String

      init(id: String, name: String)
      self.id = id
      self.name = name



      if result == "Success"
      if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
      if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
      for filterArray in getArrayProducts
      if let setFilterArray = filterArray as? [String: Any]
      self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
      self.localizationWork()
      self.tblView.reloadData()
      self.hideLoader();







      self.arr repeat because of for loop but when I use self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]
      all thing is correct but I want append data







      arrays json swift






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 25 at 6:17







      Naveen Yadav

















      asked Mar 25 at 5:58









      Naveen YadavNaveen Yadav

      178




      178




      closed as off-topic by El Tomato, Cody Gray Mar 25 at 7:05


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – El Tomato, Cody Gray
      If this question can be reworded to fit the rules in the help center, please edit the question.







      closed as off-topic by El Tomato, Cody Gray Mar 25 at 7:05


      This question appears to be off-topic. The users who voted to close gave this specific reason:


      • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Reproducible Example." – El Tomato, Cody Gray
      If this question can be reworded to fit the rules in the help center, please edit the question.






















          3 Answers
          3






          active

          oldest

          votes


















          2














          Add a check while appending new product in self.arr.



          Code:



          var arr = [ProductsModel]()

          if result == "Success"

          if let filterResponse = response[APPKEYS.responseData] as? [String: Any]

          if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray

          for filterArray in getArrayProducts

          if let setFilterArray = filterArray as? [String: Any]

          let product = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)

          if let row = self.arr.index(where: $0.id == product.id)

          self.arr[row] = product
          else

          self.arr.append(product)






          self.localizationWork()
          self.tblView.reloadData()
          self.hideLoader()





          Let me know if you are still having any issue.






          share|improve this answer
































            0














             if let filterResponse = response[APPKEYS.responseData] as? [String: Any] 
            if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
            for filterArray in getArrayProducts
            if let setFilterArray = filterArray as? [String: Any]
            self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
            //self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]



            self.localizationWork()
            self.tblView.reloadData()
            self.hideLoader();


            } ```





            share|improve this answer






























              0














              Try this



              // Put this as a property of your class
              var products: [String: ProductsModel] = [:]

              if result == "Success"
              if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
              if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
              for filterArray in getArrayProducts
              if let setFilterArray = filterArray as? [String: Any]
              self.products[setFilterArray[APPKEYS.id] as! String] = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)
              self.localizationWork()


              self.tblView.reloadData()
              self.hideLoader();








              share|improve this answer































                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2














                Add a check while appending new product in self.arr.



                Code:



                var arr = [ProductsModel]()

                if result == "Success"

                if let filterResponse = response[APPKEYS.responseData] as? [String: Any]

                if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray

                for filterArray in getArrayProducts

                if let setFilterArray = filterArray as? [String: Any]

                let product = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)

                if let row = self.arr.index(where: $0.id == product.id)

                self.arr[row] = product
                else

                self.arr.append(product)






                self.localizationWork()
                self.tblView.reloadData()
                self.hideLoader()





                Let me know if you are still having any issue.






                share|improve this answer





























                  2














                  Add a check while appending new product in self.arr.



                  Code:



                  var arr = [ProductsModel]()

                  if result == "Success"

                  if let filterResponse = response[APPKEYS.responseData] as? [String: Any]

                  if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray

                  for filterArray in getArrayProducts

                  if let setFilterArray = filterArray as? [String: Any]

                  let product = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)

                  if let row = self.arr.index(where: $0.id == product.id)

                  self.arr[row] = product
                  else

                  self.arr.append(product)






                  self.localizationWork()
                  self.tblView.reloadData()
                  self.hideLoader()





                  Let me know if you are still having any issue.






                  share|improve this answer



























                    2












                    2








                    2







                    Add a check while appending new product in self.arr.



                    Code:



                    var arr = [ProductsModel]()

                    if result == "Success"

                    if let filterResponse = response[APPKEYS.responseData] as? [String: Any]

                    if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray

                    for filterArray in getArrayProducts

                    if let setFilterArray = filterArray as? [String: Any]

                    let product = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)

                    if let row = self.arr.index(where: $0.id == product.id)

                    self.arr[row] = product
                    else

                    self.arr.append(product)






                    self.localizationWork()
                    self.tblView.reloadData()
                    self.hideLoader()





                    Let me know if you are still having any issue.






                    share|improve this answer















                    Add a check while appending new product in self.arr.



                    Code:



                    var arr = [ProductsModel]()

                    if result == "Success"

                    if let filterResponse = response[APPKEYS.responseData] as? [String: Any]

                    if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray

                    for filterArray in getArrayProducts

                    if let setFilterArray = filterArray as? [String: Any]

                    let product = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)

                    if let row = self.arr.index(where: $0.id == product.id)

                    self.arr[row] = product
                    else

                    self.arr.append(product)






                    self.localizationWork()
                    self.tblView.reloadData()
                    self.hideLoader()





                    Let me know if you are still having any issue.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 25 at 6:58

























                    answered Mar 25 at 6:10









                    Amir KhanAmir Khan

                    1,8621826




                    1,8621826























                        0














                         if let filterResponse = response[APPKEYS.responseData] as? [String: Any] 
                        if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                        for filterArray in getArrayProducts
                        if let setFilterArray = filterArray as? [String: Any]
                        self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
                        //self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]



                        self.localizationWork()
                        self.tblView.reloadData()
                        self.hideLoader();


                        } ```





                        share|improve this answer



























                          0














                           if let filterResponse = response[APPKEYS.responseData] as? [String: Any] 
                          if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                          for filterArray in getArrayProducts
                          if let setFilterArray = filterArray as? [String: Any]
                          self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
                          //self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]



                          self.localizationWork()
                          self.tblView.reloadData()
                          self.hideLoader();


                          } ```





                          share|improve this answer

























                            0












                            0








                            0







                             if let filterResponse = response[APPKEYS.responseData] as? [String: Any] 
                            if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                            for filterArray in getArrayProducts
                            if let setFilterArray = filterArray as? [String: Any]
                            self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
                            //self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]



                            self.localizationWork()
                            self.tblView.reloadData()
                            self.hideLoader();


                            } ```





                            share|improve this answer













                             if let filterResponse = response[APPKEYS.responseData] as? [String: Any] 
                            if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                            for filterArray in getArrayProducts
                            if let setFilterArray = filterArray as? [String: Any]
                            self.arr.append(ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String))
                            //self.arr = [ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)]



                            self.localizationWork()
                            self.tblView.reloadData()
                            self.hideLoader();


                            } ```






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 25 at 6:50









                            Naveen YadavNaveen Yadav

                            178




                            178





















                                0














                                Try this



                                // Put this as a property of your class
                                var products: [String: ProductsModel] = [:]

                                if result == "Success"
                                if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
                                if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                                for filterArray in getArrayProducts
                                if let setFilterArray = filterArray as? [String: Any]
                                self.products[setFilterArray[APPKEYS.id] as! String] = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)
                                self.localizationWork()


                                self.tblView.reloadData()
                                self.hideLoader();








                                share|improve this answer





























                                  0














                                  Try this



                                  // Put this as a property of your class
                                  var products: [String: ProductsModel] = [:]

                                  if result == "Success"
                                  if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
                                  if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                                  for filterArray in getArrayProducts
                                  if let setFilterArray = filterArray as? [String: Any]
                                  self.products[setFilterArray[APPKEYS.id] as! String] = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)
                                  self.localizationWork()


                                  self.tblView.reloadData()
                                  self.hideLoader();








                                  share|improve this answer



























                                    0












                                    0








                                    0







                                    Try this



                                    // Put this as a property of your class
                                    var products: [String: ProductsModel] = [:]

                                    if result == "Success"
                                    if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
                                    if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                                    for filterArray in getArrayProducts
                                    if let setFilterArray = filterArray as? [String: Any]
                                    self.products[setFilterArray[APPKEYS.id] as! String] = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)
                                    self.localizationWork()


                                    self.tblView.reloadData()
                                    self.hideLoader();








                                    share|improve this answer















                                    Try this



                                    // Put this as a property of your class
                                    var products: [String: ProductsModel] = [:]

                                    if result == "Success"
                                    if let filterResponse = response[APPKEYS.responseData] as? [String: Any]
                                    if let getArrayProducts = filterResponse[APPKEYS.products] as? NSArray
                                    for filterArray in getArrayProducts
                                    if let setFilterArray = filterArray as? [String: Any]
                                    self.products[setFilterArray[APPKEYS.id] as! String] = ProductsModel(id: setFilterArray[APPKEYS.id] as! String, name: setFilterArray[APPKEYS.name] as! String)
                                    self.localizationWork()


                                    self.tblView.reloadData()
                                    self.hideLoader();









                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Mar 25 at 9:13

























                                    answered Mar 25 at 6:52









                                    Cerlin BossCerlin Boss

                                    5,08411324




                                    5,08411324













                                        Popular posts from this blog

                                        SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                                        용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh

                                        155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해