I'm trying to encode a list of plists, and encode-json-plist-to-string doesn't appear to do it. My newbiness is not seeing a better answer then to loop through the list, and encode each plist separately, concatentate the strings together to form the array. That doesn't seem too lispy to me. Is there a better way?
On 4/7/11 Apr 7 -9:07 AM, Jim Barrows wrote:
I'm trying to encode a list of plists, and encode-json-plist-to-string doesn't appear to do it. My newbiness is not seeing a better answer then to loop through the list, and encode each plist separately, concatentate the strings together to form the array. That doesn't seem too lispy to me. Is there a better way?
From the outside, it would help if you were to provide an example of
what you want to encode, what you have tried, and what you got.
That will help list members provide better support.
cheers, r
On 4/7/2011 10:07 AM, Jim Barrows wrote:
I'm trying to encode a list of plists, and encode-json-plist-to-string doesn't appear to do it. My newbiness is not seeing a better answer then to loop through the list, and encode each plist separately, concatentate the strings together to form the array. That doesn't seem too lispy to me. Is there a better way?
I am more interested in "doesn't appear to do it". How about a small example of input and output?
kt
On Thu, Apr 7, 2011 at 4:07 PM, Jim Barrows jim.barrows@gmail.com wrote:
I'm trying to encode a list of plists, and encode-json-plist-to-string doesn't appear to do it.
Yes, because the first list is a list and not a plist.
My newbiness is not seeing a better answer then to loop through the list, and encode each plist separately, concatentate the strings together to form the array.
If you go that route, I would rather wrap a string-stream with with-output-to-string and encode each individual plist to this stream (not the -to-string functions) to avoid string concatenation at the end.
That doesn't seem too lispy to me. Is there a better way?
I suggest using the explicit encoder for more control, but then you would need to change your p-lists slightly. I assume you want the plists to be json objects, and the list to be a json array.
Both these examples give the same result:
[{"a":"c","d":"c"},{"foo":true,"bar":false}
;; More json-javascriptish terminolgy (princ (json:with-explicit-encoder (json:encode-json-to-string '(:array (:object :a "c" :d "c") (:object :foo t :bar (:false))))))
;; More lispish terminology (princ (json:with-explicit-encoder (json:encode-json-to-string '(:list (:plist :a "c" :d "c") (:plist :foo t :bar (:false))))))
Or you could use the streaming encoder.
/Henrik Hjelte