kopia lustrzana https://github.com/backface/turtlestitch
1 wiersz
1.6 KiB
XML
1 wiersz
1.6 KiB
XML
<blocks app="Snap! 5.0, http://snap.berkeley.edu" version="1"><block-definition s="listify %'jsonString'" type="reporter" category="operators"><header></header><code></code><translations>pt:os dados JSON _ em formato de lista
</translations><inputs><input type="%mlt"></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>pt:o valor com chave _ em _
</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> |