@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格式,导致输出时只能输出一个电话号码。
      建议你提供更多的代码和上下文信息,以便更准确地定位和解决该问题。
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题