2

I have a Array column in my parse Class called "serviceHistory". Its in JSON format. I am having trouble querying just this column for all my parse objects(pool Accounts).

With This code i can print out each object, but i am having trouble accessing just the service History column.

var query = PFQuery(className:"PoolAccount")
query.selectKeys(["serviceHistory"])
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in

  if let objects = objects as? [PFObject] {

    self.serviceHistory = objects
    print("these are the selectedKeys \(objects)")

   //THIS PRINTS THE WHOLE OBJECT, AND NOT JUST THE SELECTED KEY."serviceHistory"

enter image description here

I am looking to print out just the service History and can't find the right query to do it...Its an array of JSONS for Each Object.

enter image description here

this is what I'm looking for it to print out..Each Pfobject has an array of JSONs attached to it. So i think i possibly need an array of arrays to put it in? [[PFObject]]? thanks in advance.

2 Answers 2

1

The query will always return an array of PFObject, you can't limit to a single column only. You can post process the objects to extract an array containing only that column content for each object:

... = objects.valueForKey("selectedKeys")
Sign up to request clarification or add additional context in comments.

1 Comment

I tried this(maybe the wrong way) but "valueForKey" is only working for 1 PFObject and not all the pfobjects in the array...how do i get all the pfobjects array of JSON into one array?
0

Figured it out..I used a for Loop and looped through each object and then used valueForKey and appended all the numbers to an array.

    for object in objects {

      if let dataObject:AnyObject = object.valueForKey("serviceHistory") {
      let thisJson = JSON(dataObject)

      for (_, entry) in thisJson {

        if let freeChlorineJson = entry["freeChlorine"].string {

          self.freeChlorine.append(freeChlorineJson)
          print(self.freeChlorine)
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.