turtlestitch/libraries/json.xml

1 wiersz
1.6 KiB
XML

<blocks app="Snap! 5.0, http://snap.berkeley.edu" version="1"><block-definition s="listify %&apos;jsonString&apos;" type="reporter" category="operators"><header></header><code></code><translations>pt:os dados JSON _ em formato de lista&#xD;</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));&#xD;&#xD;function listify(jsonObject) {&#xD; if (jsonObject instanceof Array) {&#xD; return new List(jsonObject.map(function(eachElement) { return listify(eachElement)}));&#xD; } else if (jsonObject instanceof Object) {&#xD; return new List(Object.keys(jsonObject).map(function(eachKey) { return new List([eachKey,listify(jsonObject[eachKey])])} ))&#xD; } else {&#xD; return jsonObject&#xD; }&#xD;}</l></block><list><block var="jsonString"/></list></block></block></script></block-definition><block-definition s="value at key %&apos;key&apos; of %&apos;lst&apos;" type="reporter" category="operators"><header></header><code></code><translations>pt:o valor com chave _ em _&#xD;</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>