@Jerome 2019-09-02 10:50 采纳率: 0%
浏览 180

我现在一个程序是siebel的输入格式转成json,但是遍历时紧急联系人个电话这个集合只输出一个其他的不出来

{"phone":"18610217536","name":"实际司机1","vehicalModel":"","extenalId":"LRDV6PDC2JL605998","vehicalSeries":"拓陆者S系列","vehicleBrand":"拓陆者","vehicalType":"03","memberEmergencyContact":{"phone":"18610217536","name":"紧急联系人1"}}`

package com.siebel.json;

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.siebel.data.SiebelPropertySet;
import com.siebel.eai.SiebelBusinessService;
import com.siebel.eai.SiebelBusinessServiceException;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

@SuppressWarnings("unused")
public class EAIJSONConverter
  extends SiebelBusinessService
{
    @Override
    public void doInvokeMethod(String methodName, SiebelPropertySet input, SiebelPropertySet output)
    throws SiebelBusinessServiceException
  {
    if (methodName.equals("PropSetToJSON"))
    {
      JsonObject myJSON = new JsonObject();
      myJSON = PropertySetToJsonObject(input, myJSON);
      output.setValue(myJSON.toString());
    }
    if (methodName.equals("JSONToPropSet"))
    {
      JsonObject obj = new JsonObject();
      obj = (JsonObject)new Gson().fromJson(input.getValue(), JsonObject.class);
      JsonObjectToPropertySet(obj, output);
    }
  }

  @SuppressWarnings("rawtypes")
public static SiebelPropertySet JsonObjectToPropertySet(JsonObject obj, SiebelPropertySet ps)
  {

    Iterator<Map.Entry<String, JsonElement>> iterator = obj.entrySet().iterator();
    while (iterator.hasNext())
    {
      JsonArray jsonArray = new JsonArray();
      JsonObject jsonObject = new JsonObject();     
      Map.Entry mapEntry = (Map.Entry)iterator.next();
     // Map.Entry mapEntry = iterator.next();
      if (mapEntry != null)
      {
        JsonElement jsonelement = (JsonElement)mapEntry.getValue();
        if (jsonelement.isJsonArray())
        {
          jsonArray = jsonelement.getAsJsonArray();
          SiebelPropertySet child = new SiebelPropertySet();
          child.setType("ListOf-" + mapEntry.getKey().toString());
          SiebelPropertySet temp = new SiebelPropertySet();
          for (int i = 0; i < jsonArray.size(); i++) {
            if ((jsonArray.get(i).isJsonObject()) || (jsonArray.get(i).isJsonArray()))
            {

              temp.setType("i");
              child.addChild(JsonObjectToPropertySet(jsonArray.get(i).getAsJsonObject(), temp));
            }
            else
            {
              child.setProperty("i", jsonArray.get(i).getAsString());
            }
          }
          ps.addChild(child);
        }
        else if (jsonelement.isJsonObject())
        {
          jsonObject = jsonelement.getAsJsonObject();
          SiebelPropertySet child = new SiebelPropertySet();
          child.setType(mapEntry.getKey().toString());
          ps.addChild(JsonObjectToPropertySet(jsonObject, child));
        }
        else
        {
          ps.setProperty(mapEntry.getKey().toString(), mapEntry.getValue().toString().replace("\"", ""));
        }
      }
    }
    return ps;
  }

  public JsonObject PropertySetToJsonObject(SiebelPropertySet ps, JsonObject jObj)
  {
    JsonObject siebJSON = new JsonObject();

    String propName = ps.getFirstProperty();
    while (propName != "")
    {
      String propVal = ps.getProperty(propName);
      siebJSON.addProperty(propName, propVal);
      propName = ps.getNextProperty();
    }
    JsonObject child = new JsonObject();
    for (int i = 0; i < ps.getChildCount(); i++)
    {

      child = PropertySetToJsonObject(ps.getChild(i), child);
      siebJSON.add(ps.getChild(i).getType(), child);
    }
    return siebJSON;
  }

  public static void main(String[] args)
  {
    SiebelPropertySet input = new SiebelPropertySet();
    SiebelPropertySet output = new SiebelPropertySet();

    input.setProperty("excelname", "jbs.xlsx");
    input.setProperty("sheetID", "1");
    input.setProperty("skip", "0");
    input.setValue("{status:true,returnCode:0,message:Registeruserissuccess!,user:{brandCode:T,mobile:13900000000,customerName:姓名,sourceChannel:05,dealerCode:000001,memberNo:000001,idType:IdentityCard,email:test@qq.com,idCode:230111111111111111}}");

    EAIJSONConverter jbs = new EAIJSONConverter();
    try
    {
      jbs.doInvokeMethod("PropSetToJSON", input, output);
    }
    catch (SiebelBusinessServiceException e)
    {
      e.printStackTrace();
    }
    System.out.print(output);
  }
}

  • 写回答

1条回答 默认 最新

  • 憧憬blog 2023-06-26 17:38
    关注

    对于这个问题,我需要更多的上下文信息才能给出准确的答复。但我可以提供一些可能导致该问题的原因:

    1. 遍历时可能只选择了紧急联系人集合中的一个电话号码,而没有遍历所有的电话号码。
    2. 紧急联系人集合中的电话号码可能存在重复或者为空的情况,在输出时可能被过滤掉了。
    3. 在转换过程中,紧急联系人集合可能被错误解析或者未正确转换为Json格式,导致输出时只能输出一个电话号码。
      建议你提供更多的代码和上下文信息,以便更准确地定位和解决该问题。
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?