<br><br><div class="gmail_quote">On Thu, Apr 7, 2011 at 4:07 PM, Jim Barrows <span dir="ltr"><<a href="mailto:jim.barrows@gmail.com">jim.barrows@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I'm trying to encode a list of plists, and encode-json-plist-to-string doesn't appear to do it.</blockquote><div><br>Yes, because the first list is a list and not a plist. <br> <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div>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. </div></blockquote><div><br>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.<br>
<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div> That doesn't seem too lispy to me.</div>
<div>Is there a better way?<br clear="all"></div></blockquote><div> </div><div>I suggest using the explicit encoder for more control, but then you would need to change your p-lists slightly.<br>I assume you want the plists to be json objects, and the list to be a json array. <br>
<br>Both these examples give the same result:<br><br>[{"a":"c","d":"c"},{"foo":true,"bar":false}<br><br>;; More json-javascriptish terminolgy <br></div>(princ <br>
   (json:with-explicit-encoder <br>      (json:encode-json-to-string <br>         '(:array (:object :a "c" :d "c")<br>                     (:object :foo t :bar (:false))))))<br><br>;; More lispish terminology<br>
(princ <br>   (json:with-explicit-encoder <br>      (json:encode-json-to-string <br>         '(:list (:plist :a "c" :d "c")<br>                 (:plist :foo t :bar (:false))))))<br><br>Or you could use the streaming encoder.<br>
<br>/Henrik Hjelte<br>
</div>