简一_hz 2016-06-29 01:25 采纳率: 0%
浏览 2524
已采纳

怎么将json存储转成xml数据格式存储

怎么将下面的json存储转成xml数据格式存储


 private String generateTableInfo(Uri uri, String where, String filename, boolean needIds) {
        JSONArray jAResult = new JSONArray();
        String ids = "";
        Cursor c = mContext.getContentResolver().query(uri, null, where, null, null);
        if (c != null) {
            try {
                if (c.moveToFirst()) {
                    for (int i = 0; i < c.getCount(); i++) {
                        c.moveToPosition(i);
                        JSONObject jsonO = new JSONObject();
                        int ColumnCount = c.getColumnCount();
                        for (int j=0; j<ColumnCount; j++) {
                            if (uri.equals(CaseInfo.CONTENT_URI) && c.getColumnName(j).equals(CaseInfo._PATH)) {
                                String filepath = c.getString(j);
                                File file = new File(filepath);
                                zipFilelist.add(file);
                                jsonO.put(c.getColumnName(j), file.getName());
                            } else {
                                jsonO.put(c.getColumnName(j), c.getString(j));
                            }
                            if (needIds && uri.equals(AttachInfo.CONTENT_URI) && c.getColumnName(j).equals(AttachInfo._BYTEID)) {
                                if (ids.length() == 0) {
                                    ids = "(\'" + c.getString(j);
                                } else {
                                    ids += "\',\'" + c.getString(j);
                                }
                            }
                        }
                        jAResult.put(jsonO);
                    }
                    if (needIds && uri.equals(AttachInfo.CONTENT_URI)) {
                        if (ids.length() != 0) {
                            ids += "\')";
                        }
                    }
                }
            } catch (Exception e) {
            //  TODO: handle exception
                Log.i(e.getMessage());
            } finally {
                c.close();
            }
        }
  • 写回答

4条回答 默认 最新

  • GreenRookie 2016-06-29 02:39
    关注

    Document do=DocumentHelper,createDocument();
    do.setXMLEncoding("UTF-8");
    do.setName("?XML");
    Element root=do.addElement("root");//自己定义
    Element user=root.addElement("userid");//自己定义
    user.addAttribute("key",value);
    //根据这种格式 把json转换成list数据后遍历进去

    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?