JIMSMITH 0 Posted September 19 Is there a way to remove pairs, as in all pairs, from a tjsonobject? Looking for something like tjsonobject.clear. Share this post Link to post
pyscripter 694 Posted September 19 There is: function TJSONObject.RemovePair(const PairName: string): TJSONPair; To clear all pairs: JsonObject.SetPairs([]); You could also Free the JsonObject and create a new one. Share this post Link to post
JIMSMITH 0 Posted September 19 If I try the setpairs above I receive the message below when compiling. [dcc32 Error] UfrmChannelConfig.pas(161): E2010 Incompatible types: 'System.Generics.Collections.TList<System.JSON.TJSONPair>' and 'Set' Share this post Link to post
Dave Nottage 562 Posted September 19 54 minutes ago, JIMSMITH said: Is there a way to remove pairs, as in all pairs, from a tjsonobject? Not "out of the box". You could perhaps do this: while LJSONObject.Count > 0 do LJSONObject.RemovePair(LJSONObject.Pairs[0].JsonString.Value).Free; Share this post Link to post
Remy Lebeau 1427 Posted September 19 (edited) 1 hour ago, pyscripter said: To clear all pairs: JsonObject.SetPairs([]); That won't work. SetPairs() expects a list, not a Set or an array. You would need to use this instead: JsonObject.SetPairs(TList<TJSONPair>.Create); This is because SetPairs() takes ownership of the new list, freeing the old list. The list can't be nil or else you risk crashes on future operations on the TJsonObject. Edited September 19 by Remy Lebeau 2 Share this post Link to post