Question

first the structure , then the explain


•[J]           (json root)
••[A]         (array of A object)
•••[A1]     (data of A1)
•••[A2]     (data of A2)
•••[A3]     ( ... )
•••• [A3.B]    (array of B object , member inside A)
•••••• [B1]   (data of B1)
•••••• [B2]   (data of B2)
•••••• [B3]   ( ... )
••••••••[B3.A]    (again array of A , but this time , it's inside B , hm ! Houston, we have a problem!!! )


() so , as you can see , I have a hard problem to get the inner/nested A array which is inside B.
() this behavior repeat itself more than this once , in object C (not objective-C), etc`
() The structure of the data that is retrieve from the server is well known
() any thoughts ? thanks


UPDATE - Demo data as requested !

{
    "arrayOfA": [
        {
            "a_Property": "Name1",
            "array_Of_B": []
        },
        {
            "a_Property": "Name2",
            "array_Of_B": []
        },
        {
            "a_Property": "Name3",
            "array_Of_B": [
                {
                    "b_Property": 10,
                    "array_Of_A": []
                },
                {
                    "b_Property": 15,
                    "array_Of_A": []
                },
                {
                    "b_Property": 20,
                    "array_Of_A": [
                        {
                            "a_Property": "Name4",
                            "array_Of_B": []
                        },
                        {
                            "a_Property": "Name5",
                            "array_Of_B": []
                        },
                        {
                            "a_Property": "Name6",
                            "array_Of_B": []
                        }
                    ]
                }
            ]
        }
    ]
}

Was it helpful?

Solution

A mapping can refer both to itself and to the mappings to deal with recursive relationships. The only thing to consider is to create all of the mappings and associate them at the same time (don't call a method to create a mapping as you are likely to end up with an infinite call loop).


In pseudo code:

Mapping *myMapping = ...;
[myMapping addRelationshipFor:... withMapping:myMapping];

which will create a mapping to deal with an object which contains other copies of the same object. The same approach can be taken when there is a recursive relationship between 2 objects:

Mapping *myMapping = ...;
Mapping *myOtherMapping = ...;
[myMapping addRelationshipFor:... withMapping:myOtherMapping];
[myOtherMapping addRelationshipFor:... withMapping:myMapping];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top