I’ve got a json like this:
{
"questionTemplate": "1",
"answerTemplate": "1",
"placeholders": {
"qd0": "1",
"qd1": "2",
"qd2": "2",
"qd3": "3",
"qd4": "5",
"qd5": "2",
"qd6": "3",
"qd7": "3",
"ad0": "60",
"ad1": "{{qd1}}+{{qd3}}",
"ad2": "{{qd1}}+{{qd3}}+{{ad1}}",
"ad3": "5",
"ad4": "10",
"ad5": "3",
"ad6": "10",
"ad7": "9"
},
"answeres": [
{
"r": "({{qd1}}+{{ad7}})*{{ad2}}"
}
]
}
Where there’s a string like {{qd1}}+{{qd3}} I should compute the sum of the values at the keys qd1 and qd2. So I should substitute, with mustache, the values with the one stored in the referenced keys.
My problem is that this it completely generic: one json could be like this, another one will be different!
How could I do?
I was trying to understand how to use
+ (id)templateFromString:(NSString *)templateString
error:(NSError **)error;
and
- (NSString *)renderObjectsFromArray:(NSArray *)objects error:(NSError **)error;
but i’m not sure if is what I need
thank you very much!
I’m the author of GRMustache. Could you please provide 1. some real (not too big) data and templates, 2. the code you have written so far, 3. the expected result? I’ll help you the best I can.