首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    开发:随笔记录之 Json字符串 与 List、HashMap对象的转换

    import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import net.sf.json.JSONArray; import net.sf.json.JSONObject; import net.sf.json.JsonConfig; import net.sf.json.util.JSONUtils; public class JsonParser { /** * json字符串 转成 map * * @param jsonStr * @return * @throws Exception */ public static HashMap<String, JsonValue> parse(String jsonStr) { if (jsonStr == null || "".equals(jsonStr)) { return null; } HashMap<String, JsonValue> retMap = null; try { retMap = new HashMap<String, JsonValue>(); JSONObject json = JSONObject.fromObject(jsonStr); Map<String, Object> tmpMap = (Map<String, Object>) JSONObject .toBean(json, Map.class); for (Map.Entry<String, Object> entry : tmpMap.entrySet()) { JsonValue tmp = parseRec(entry.getValue(), 0); retMap.put(entry.getKey(), tmp); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return retMap; } /** * json字符串 转成 List * * @param jsonStr * @return * @throws Exception */ public static List<HashMap<String, JsonValue>> parseList(String jsonStr) { if (jsonStr == null || "".equals(jsonStr)) { return null; } List<HashMap<String, JsonValue>> retList = new ArrayList<HashMap<String, JsonValue>>(); JSONArray data = JSONArray.fromObject(jsonStr); for (int i = 0; i < data.size(); i++) { HashMap<String, JsonValue> retMap = new HashMap<String, JsonValue>(); JSONObject json = (JSONObject) data.get(i); Map<String, Object> tmpMap = (Map<String, Object>) JSONObject .toBean(json, Map.class); for (Map.Entry<String, Object> entry : tmpMap.entrySet()) { JsonValue tmp = parseRec(entry.getValue(), 0); retMap.put(entry.getKey(), tmp); } retList.add(retMap); } return retList; } /** * HashMap<String, JsonValue> map 转成 json字符串 * * @param jsonStr * @return * @throws Exception */ public static String parse(HashMap<String, JsonValue> m

    03

    word导出03

    public static void exportWordImg(String wordpath,List<String> contentlist,String[] imglist) throws Exception{         exportQuestionWord t=new exportQuestionWord();         WordprocessingMLPackage wordMLPackage = t.createWordprocessingMLPackage();         MainDocumentPart mp = wordMLPackage.getMainDocumentPart();         ObjectFactory factory = Context.getWmlObjectFactory();         //图片页眉         //Relationship relationship =t.createHeaderPart(wordMLPackage, mp, factory);         //文字页眉         //Relationship relationship =t.createTextHeaderPart(wordMLPackage, mp, factory, "页眉", JcEnumeration.CENTER);         //t.createHeaderReference(wordMLPackage, mp, factory, relationship);         t.addParagraphTest(wordMLPackage, mp, factory,contentlist,imglist);         //t.addPageBreak(wordMLPackage, factory);         //t.createNormalTableTest(wordMLPackage, mp, factory);         //页脚         //relationship =t.createFooterPageNumPart(wordMLPackage, mp, factory);         //t.createFooterReference(wordMLPackage, mp, factory, relationship);         t.saveWordPackage(wordMLPackage, new File(wordpath));     }     public void addParagraphTest(WordprocessingMLPackage wordMLPackage,                                  MainDocumentPart t, ObjectFactory factory,List<String> contentlist,String[] imglist) throws Exception {         RPr titleRPr = getRPr(factory, "黑体", "000000", "30", STHint.EAST_ASIA,                 true, false, false, false);         RPr boldRPr = getRPr(factory, "宋体", "000000", "24", STHint.EAST_ASIA,                 true, false, false, false);         RPr fontRPr = getRPr(factory, "宋体", "000000", "22", STHint.EAST_ASIA,                 false, false, false, false);         P paragraph=factory.createP();         Text txt = null;         R run=null;         File file=null;         InputStream is=null;         if(contentlist!=null || contentlist.size()>0){         for (int i = 0; i < contentlist.size(); i++) {             if(contentlist.get(i).contains("22.发生肺水肿时的应急处理错误的是")){

    01
    领券