kopia lustrzana https://github.com/backface/turtlestitch
added JSON library
rodzic
6fee9698ed
commit
7d823067d0
|
@ -19,3 +19,4 @@ pixel_module.xml Pixels manipulate costumes pixel-wise.
|
|||
audioComp_module.xml Audio Comp analyze, manipulate and generate sound samples.
|
||||
atomic_HOFs_module.xml "Bigger" Data [EXPERIMENTAL] crunch large lists very fast
|
||||
make-variables.xml create variables in program declare global or sprite-local variables in a script
|
||||
json.xml Deal with JSON data Turn JSON strings into lists with the listify block, then retrieve data out of them by using the value at key block.
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
<blocks app="Snap! 4.1, http://snap.berkeley.edu" version="1"><block-definition s="listify %'jsonString'" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%s"></input></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list><l>jsonString</l></list><l>return listify(JSON.parse(jsonString));

function listify(jsonObject) {
 if (jsonObject instanceof Array) {
 return new List(jsonObject.map(function(eachElement) { return listify(eachElement)}));
 } else if (jsonObject instanceof Object) {
 return new List(Object.keys(jsonObject).map(function(eachKey) { return new List([eachKey,listify(jsonObject[eachKey])])} ))
 } else {
 return jsonObject
 }
}</l></block><list><block var="jsonString"/></list></block></block></script></block-definition><block-definition s="value at key %'key' of %'lst'" type="reporter" category="operators"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%l"></input></inputs><script><block s="doWarp"><script><block s="doForEach"><l>each item</l><block var="lst"/><script><block s="doIf"><block s="reportEquals"><block s="reportListItem"><l>1</l><block var="each item"/></block><block var="key"/></block><script><block s="doReport"><block s="reportListItem"><l>2</l><block var="each item"/></block></block></script></block></script></block></script></block><block s="doReport"><l></l></block></script></block-definition></blocks>
|
Ładowanie…
Reference in New Issue