0

I try to send a file list from PHP to my Java program. I thought JSON was a good idea so I ended up with this JSON Array:

{"0":"File1.png","1":"File2.png","2":"File3.html"}

Now I want Java to show the files on a showMessageDialog like this:

Your Files:
File1.png 
File2.png
File3.html

Can anyone help me with this?

What I have:

String fileurl = "http://my.website/the/json/file/list";
String jsonStr = getHTML(fileurl); //getHTML => Gets the JSON Code 
System.out.println(jsonStr); //Just for testing reasons
//JSON Array to Java Array here?
JTextArea ausgabeBereich = new JTextArea(10, 10); //Creating a JTextArea 
JScrollPane scroller = new JScrollPane(ausgabeBereich); //With a ScrollPane
String ausgabe = "Your Files\n";
ausgabe += //Adding the files here?
ausgabeBereich.setText(ausgabe); //Set the text of the TextArea
JOptionPane.showMessageDialog(null,scroller,"Dateien",
JOptionPane.PLAIN_MESSAGE);  // Shows the Windows
Pshemo
  • 122,468
  • 25
  • 185
  • 269
  • Do you get any errors? What is your question/problem? – Pshemo Aug 09 '15 at 18:51
  • 1
    `{"0":"File1.png","1":"File2.png","2":"File3.html"}` is not an array its an OBJECT with 3 properties [How to parse JSON in JAVA](http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – RiggsFolly Aug 09 '15 at 18:51
  • If you want to pass an array use `["0":"File1.png","1":"File2.png","2":"File3.html"]` But I would imagine JAVA would be just as happy with an object as long as you parse the string into one first. – RiggsFolly Aug 09 '15 at 18:54
  • do some JSON parsing before `ausgabe += //Adding the files here?` as told by @RiggsFolly – Yogesh Seralia Aug 09 '15 at 19:22

0 Answers0