J
jmls
Guest
11.3 (although will probably work on 11.x) I'm trying to merge two json objects together. The code below seems to work, but I was wondering if there is any other (faster, more efficient) way. /** merge source object into target object * @param : source json object * @param : target json object * @returns : void */ method void mergeJson(oSource as JsonObject,oTarget as JsonObject): def var lv_i as int no-undo. def var lv_name as char extent no-undo. /** get all the defined properties of the source object */ assign lv_name = oSource:getnames(). /** loop through all properties of the source object * and try to add the property to the target object * using no-error to supress any error if the target * object already has the property defined */ do lv_i = 1 to extent(lv_name): /** add to the target object using the appropriate getter on the source object */ case oSource:GetType(lv_name[lv_i]): when JsonDataType:ARRAY then oTarget:add(lv_name[lv_i],oSource:GetJsonArray(lv_name[lv_i])) no-error. when JsonDataType:BOOLEAN then oTarget:add(lv_name[lv_i],oSource:GetLogical(lv_name[lv_i])) no-error. when JsonDataType:NUMBER then oTarget:add(lv_name[lv_i],oSource:GetDecimal(lv_name[lv_i])) no-error. when JsonDataType:OBJECT then oTarget:add(lv_name[lv_i],oSource:GetJsonObject(lv_name[lv_i])) no-error. when JsonDataType:string then oTarget:add(lv_name[lv_i],oSource:GetCharacter(lv_name[lv_i])) no-error. /** yikes. throw a wobbly */ otherwise undo, throw new AppError(substitute("Unknown json datatype &1",oSource:GetType(lv_name[lv_i])),0). end case. end. end method.
Continue reading...
Continue reading...