king,
js := TlkJSONObject.Create();
js := TlkJSON.ParseText(jsonstr) as TlkJSONObject;
if js.Field['name'].Field['surname'].SelfType <> jsNull then
surname := String(js.Field['name'].Field['surname'].Value);
The equivalent version of with my library would be:
N := TJsonNode.Create;
if N.TryParse(S) and (N.Find('name/surname') <> nil) then
SurName := N.Find('name/surname').AsString;
With regards to speed, I am considering an experiment for my own curiosity. Here is how and what I would test.
1) Time parsing a large JSON structure thousands of times.
2) Remove the TJsonNode create during the parsing, internally overwriting the same node over and over again and repeat the same test.
3) Remove the internal TList and add, and repeat the test again yet again and note the time.
This should give me a good base line to understand how much time it take the FPC to parse JSON with my library, first as it is now, second as it would be with some type of object pooling, and third with a fixed size list shared among all nodes.
If the times show a marked difference in speed, then adding pooling and a shared list might be a worthwhile enhancement. Also, I may test against uLkJSON. I've look at its source code and I'll be curious to see the speed difference.
Thank you for your replies.