Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • mismatch in json while converting

    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 583
    Answer it

    can help me to resolve this. Am trying to convert the xml to json but the json values is not same as xml there is a mismatch in the values. Here is the snippet

    @SuppressWarnings("unused")
    
    public static void main (String args[]) throws IOException{
    
    int PRETTY_PRINT_INDENT_FACTOR = 1;
    
    File file=new File("D:\\Input\\");
    
    File[] allFiles=file.listFiles();
    
    for(int i=0;i<allFiles.length;i++){
    
    if(allFiles[i].getAbsolutePath().endsWith("xml")){
    
    InputStream inputStream=new FileInputStream(allFiles[i]);
    
    StringBuilder builder = new StringBuilder();
    
    int ptr = 0;
    
    while ((ptr = inputStream.read()) != -1 )
    
    {
    
    builder.append((char) ptr);
    
    }
    
    String xml = builder.toString();
    
    JSONObject jsonObj = XML.toJSONObject(xml);
    
    String jsonString=jsonObj.toString(PRETTY_PRINT_INDENT_FACTOR);
    
    System.out.println();
    
    
    
    byte[] contentBytes=jsonString.getBytes();
    
    System.out.println(jsonString);
    
    File f=new File("D:\\Important_Docs\\filewrite.txt");
    
    FileOutputStream fop=new FileOutputStream(f);
    
    fop.write(contentBytes);
    
    }
    
    
    }
    
    }

 2 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: