Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
45
Task/JSON/Lingo/json-1.lingo
Normal file
45
Task/JSON/Lingo/json-1.lingo
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//--------------------------------------
|
||||
// Simple (unsafe) JSON decoder based on eval()
|
||||
// @param {string} json
|
||||
// @return {any}
|
||||
//--------------------------------------
|
||||
function json_decode (json){
|
||||
var o;
|
||||
eval('o='+json);
|
||||
return _json_decode_val(o);
|
||||
}
|
||||
|
||||
function _json_decode_val (o){
|
||||
if (o==null) return undefined;
|
||||
switch(typeof(o)){
|
||||
case "object":
|
||||
if (o instanceof Array){
|
||||
var v = list();
|
||||
var cnt = o.length;
|
||||
for (i=0;i<cnt;i++){
|
||||
v.add(_json_decode_val(o[i]));
|
||||
}
|
||||
}else{
|
||||
var v = propList();
|
||||
for (var i in o){
|
||||
var p = i;
|
||||
v.setAProp(_json_decode_val(p), _json_decode_val(o[i]));
|
||||
}
|
||||
}
|
||||
return v;
|
||||
case "string":
|
||||
// optional support of special Lingo data type 'symbol' unknown to JavaScript
|
||||
if (o.substr(0,7)=='__sym__') return symbol(o.substr(7));
|
||||
return o;
|
||||
default:
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
||||
function _json_escape_string (str){
|
||||
var hash={"\\":"\\\\", "/":"\\/", "\n":"\\n", "\t":"\\t", "\r":"\\r", "\b":"\\b", "\f":"\\f", "\"":"\\\""};
|
||||
var patt = "["; for (i in hash) patt+=i;patt+="]";
|
||||
return str.replace(RegExp(patt, "g"), function(c){
|
||||
return hash[c]
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue