json = '["a", "B", "C"]'
puts "Unsafe #{unsafe_json
(json).inspect}"
#输出Unsafe
["a", "B", "C"]
json = 'puts "Danger
Will Robinson"'
puts "Unsafe #{unsafe_json
(json).inspect}"
module SafeJSON
require 'monitor'
def SafeJSON.build_safe_json
ret = nil
waiter = ''
waiter.extend(MonitorMixin)
wait_cond = waiter.new_cond
Thread.start do
$SAFE = 4
ret = Proc.new {|json|
eval(json.gsub(/(["'])/s*:/s*
(['"0-9tfn/[{])/){"#{$1}=>#{$2}"}) }
waiter.synchronize do wait_cond.signal
end
end
waiter.synchronize do wait_
cond.wait_while { ret.nil? } end
return ret
end
@@parser = SafeJSON.build_safe_json
# Safely parse the JSON input
def SafeJSON.parse(input)
@@parser.call(input)
rescue SecurityError
return nil
end
end
peoples=SafeJSON.parse('
{"peoples":[{"name":"site120","
email":"site120@163.com","sex":"男"},
{"name":"site120_2","email":"site1
20@163.com_2","sex":"男_2"}]}')
puts peoples["peoples"][1]["name"]
#输出site120_2
gem install json_pure
require "open-uri"
require 'json'
def index
uri = '*****'
response = nil
begin
open(uri) do |http|
response = http.read
end
@json = JSON::parse(response)
rescue => text
# 异常处理
logger.error("GetMailListserror=" + text)
flash.now[:error] = '获取邮件列表失败。'
end
end
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有