ScriptControl与htmlfile 怎么列出属性保存到CURSOR?
var data_1={"traces": {"accepttime":"2016-12-04 13:23:00","acceptaddress":"北京市","remark":"北京邮政速递上地区域分公司清华营投部安排投递,预计23:59:00前投递"}};var data_2={"traces": [{"accepttime":"2016-12-04 13:23:00","acceptaddress":"北京市","remark":"北京邮政速递上地区域分公司清华营投部安排投递,预计23:59:00前投递"}] };
第二种可能好列出,第一种如何列出所有属性
目前找到一种方法:
LPARAMETERS cJSON
TEXT TO cJSON TEXTMERGE NOSHOW
{"traces": [{"accepttime":"2016-12-04 13:23:00",
"acceptaddress":"北京市",
"remark":"北京邮政速递上地区域分公司清华营投部安排投递,预计23:59:00前投递"}]}
ENDTEXT
TEXT TO cJSON TEXTMERGE NOSHOW
{"traces": {"accepttime":"2016-12-04 13:23:00",
"acceptaddress":"北京市",
"remark":"北京邮政速递上地区域分公司清华营投部安排投递,预计23:59:00前投递"}}
ENDTEXT
TEXT TO jsCode TEXTMERGE NOSHOW
var json_data=<<cJSON>>;
function funArray(obj){
var ret=""
for(var key in obj)
for (var o in obj[key]){
ret = ret + "," + o + ":" + obj[key][o];
}
return ret;
}
function funObject(obj){
var ret=""
for (var o in obj){
ret = ret + "," + o + ":" + obj[o];
}
return ret;
}
//判断是否是数组
function isArray(obj) {
return Object.prototype.toString.call(obj) == '[object Array]';
}
//判断是否是对象
function isObject(obj) {
return Object.prototype.toString.call(obj) == '[object Object]';
}
ENDTEXT
cJScript2FOX = CREATEOBJECT("ScriptControl") &&("MSScriptControl.ScriptControl")
cJScript2FOX.Language = "JavaScript"
cJScript2FOX.addCode(jsCode)
oJsonNodes=cJScript2FOX.CodeObject.json_data.traces
CREATE CURSOR JSON_Cursor (accepttime c(30), acceptaddress c(30), remark c(200))
DO CASE
CASE cJScript2FOX.run("isArray",oJsonNodes) &&数组
FOR EACH oJsonNode IN oJsonNodes
INSERt INtO JSON_Cursor VaLUES (oJsonNode.accepttime, oJsonNode.acceptaddress, oJsonNode.remark)
ENDFOR
CASE cJScript2FOX.run("isObject",oJsonNodes) &&对象
INSERt INtO JSON_Cursor VaLUES (oJsonNodes.accepttime, oJsonNodes.acceptaddress, oJsonNodes.remark)
ENDCASE
SELECt * FROM JSON_Cursor
[此贴子已经被作者于2023-8-19 14:28编辑过]