0xjmp / ObjectMapper-Realm

An ObjectMapper extension that serializes arbitrary JSON into Realm's List class
Other
178 stars 43 forks source link

Dictionary parsing using Realm? #1

Closed ranjitDhiman1990 closed 8 years ago

ranjitDhiman1990 commented 8 years ago

How do I parse a Dictionary response using Realm? Please help with example.

Here is my response -

{ questions = ( { "_id" = qId1; answerKey = 1001; details = { createdBy = { avatar = "http://icons.iconarchive.com/icons/mattahan/ultrabuuf/256/TV-Smith-icon.png"; name = "Sir Devender"; userId = 1; }; createdOn = ""; description = { files = ""; text = "A train running at the speed of 60 km/hr crosses a pole in 9 seconds. What is the length of the train?"; }; options = ( { file = ""; num = 1; text = "120 metres"; type = text; }, { file = ""; num = 2; text = "180 metres"; type = text; }, { file = ""; num = 3; text = "324 metres"; type = text; }, { file = ""; num = 4; text = "150 metres"; type = text; } ); type = mcq; }; }, { "_id" = qId2; answerKey = 1000; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "A train 125 m long passes a man, running at 5 km/hr in the same direction in which the train is going, in 10 seconds. The speed of the train is:"; }; options = ( { file = ""; num = 1; text = "45 km/hr"; type = text; }, { file = ""; num = 2; text = "50 km/hr"; type = text; }, { file = ""; num = 3; text = "54 km/hr"; type = text; }, { file = ""; num = 4; text = "55 km/hr"; type = text; } ); type = mcq; }; }, { "_id" = qId3; answerKey = f; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "Electrons are larger than molecules."; }; type = tf; }; }, { "_id" = qId4; answerKey = 1001; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "Suppose you are a mathematics professor who wants to determine whether or not your teaching of a unit on probability has had a significant effect on your students. You decide to analyze their scores from a test they took before the instruction and their scores from another exam taken after the instruction. Which of the following t-tests is appropriate to use in this situation?"; }; options = ( { file = ""; num = 1; text = "Dependent samples."; type = text; }, { file = ""; num = 2; text = "Heterogenous samples."; type = text; }, { file = ""; num = 3; text = "Homogenous samples."; type = text; }, { file = ""; num = 4; text = "Independent samples."; type = text; } ); type = mcq; }; }, { "_id" = qId5; answerKey = 1000; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "A nurse is assessing a client who has pneumonia. Which of these assessment findings indicates that the client does NOT need to be suctioned?"; }; options = ( { file = ""; num = 1; text = "Diminished breath sounds."; type = text; }, { file = ""; num = 2; text = "Absence of adventitious breath sounds."; type = text; }, { file = ""; num = 3; text = "Inability to cough up sputum."; type = text; }, { file = ""; num = 4; text = "Wheezing following bronchodilator therapy."; type = text; } ); type = mcq; }; }, { "_id" = qId6; answerKey = f; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "All trees except pine trees molt their leaves in the fall."; }; type = tf; }; }, { "_id" = qId7; answerKey = 1001; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "What is the average effective radiation dose from chest CT?"; }; options = ( { file = ""; num = 1; text = "1-8 mSv"; type = text; }, { file = ""; num = 2; text = "8-16 mSv"; type = text; }, { file = ""; num = 3; text = "16-24 mSv"; type = text; }, { file = ""; num = 4; text = "24-32 mSv"; type = text; } ); type = mcq; }; }, { "_id" = qId8; answerKey = 1000; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "Idaho is widely known for its:"; }; options = ( { file = ""; num = 1; text = Apples; type = text; }, { file = ""; num = 2; text = Corn; type = text; }, { file = ""; num = 3; text = Potatoes; type = text; }, { file = ""; num = 4; text = Wheat; type = text; } ); type = mcq; }; }, { "_id" = qId9; answerKey = f; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "Water is less dense in its liquid state."; }; type = tf; }; }, { "_id" = qId10; answerKey = 1001; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "Which of the following artists is known for painting the ceiling of the Sistine Chapel?"; }; options = ( { file = ""; num = 1; text = Botticelli; type = text; }, { file = ""; num = 2; text = "da Vinci"; type = text; }, { file = ""; num = 3; text = Michelangelo; type = text; }, { file = ""; num = 4; text = Raphael; type = text; } ); type = mcq; }; }, { "_id" = qId11; answerKey = 1000; details = { createdBy = { avatar = "http://findicons.com/files/icons/1072/face_avatars/300/a02.png"; name = "Sir Tarun"; userId = 2; }; createdOn = ""; description = { files = ""; text = "The term operant conditioning refers to the learning situation in which:"; }; options = ( { file = ""; num = 1; text = "A familiar response is associated with a new stimulus."; type = text; }, { file = ""; num = 2; text = "Individual associations are linked together in sequence."; type = text; }, { file = ""; num = 3; text = "The learner\U2019s response leads to reinforcement."; type = text; }, { file = ""; num = 4; text = "Verbal responses are made to verbal stimuli."; type = text; } ); type = mcq; }; }, { "_id" = qId12; answerKey = f; details = { createdBy = { "_id" = tempid6; avatar = "http://icons.iconarchive.com/icons/hopstarter/superhero-avatar/256/Avengers-Black-Widow-icon.png"; name = "Alecto Carrow"; role = ta; }; createdOn = ""; description = { files = ""; text = "Dieting combined with consistent exercise will usually aid in weight loss."; }; type = tf; }; } ); submission = { qId1 = { answerString = 1001; }; qId10 = { answerString = 1001; }; qId11 = { answerString = 1001; }; qId12 = { answerString = f; }; qId2 = { answerString = 1001; }; qId3 = { answerString = f; }; qId4 = { answerString = 1001; }; qId5 = { answerString = 1001; }; qId6 = { answerString = f; }; qId7 = { answerString = 1001; }; qId8 = { answerString = 1001; }; qId9 = { answerString = f; }; }; }

akovalov commented 8 years ago

@ranjitDhiman1990 this is not an issue, please refer to corresponding docs https://realm.io/docs/swift/latest/ and https://github.com/Hearst-DD/ObjectMapper.