• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Get json data on android client listener

ware4u

Lurker
I have code socket io js like this

JavaScript:
socket.on('clienstconnected',function(data

var roomlist={id:'1',roomname:'room1',id:'2',roomname:'room2',id:'3',roomname:'room3'};

socket.emit("clienstconnected",roomlist

});
and Android code like this

JavaScript:
private Emitter.Listener onClienstConnected1 = new Emitter.Listener() {
@override
public void call(Object... args) {
JSONObject data = (JSONObject) args[0];

try{

System.out.println(args[0].toString());
}

catch (Exception e) { Log.e("My App", "Could not parse malformed JSON: \"" + data + "\"");}

}
};
and System.out.println print only one item is : id:'3',roomname:'room3' not all of Json item as I want

Thk for reading my topic
 
You need a loop. Try this (uncompiled, and untested)

Code:
private Emitter.Listener onClienstConnected1 = new Emitter.Listener() {
@override
public void call(Object... args) {
    JSONObject data = (JSONObject) args[0];
    try {
        for (int i=0; i < args.length; i++) {
            System.out.println(args[i].toString());
        }
    }
    catch (Exception e) { Log.e("My App", "Could not parse malformed JSON: \"" + data + "\"");}
  }
};
 
I can't find tab logcat but I have a watch window
 

Attachments

  • watch_window.png
    watch_window.png
    56.7 KB · Views: 108
thk lv426, the json string maybe problem I replace new json string it's ok,below is new json string

{
"name":"John",
"age":30,
"cars":[ "Ford", "BMW", "Fiat" ]
}

Mod close topic please,thk all
 
Back
Top Bottom