1.如果传递对象:
@ReactMethod
public void getUserInfo(Callback callback){
WritableMap map = Arguments.createMap();
map.putString("islogin",MainApplication.getApplication().isLogin()+"");
map.putString("nick_name", getApplication().getNickname());
map.putString("user_name", getApplication().getUsername());
map.putString("avatar_url", getApplication().getTouxiang());
map.putString("access_token",getApplication().getAccess_token());
map.putString("uid",getApplication().getUid()+"");
map.putString("gender_str", getApplication().getSex());
callback.invoke(map);
}
2.如果传递json数组:
@ReactMethod
public void getAllGameList(Callback callback){
ArrayList<Game> games = MainApplication.getApplication().getGames();
WritableArray arrays = Arguments.createArray();
for (Game game:games){
WritableMap map = Arguments.createMap();
map.putString("name",game.name);
map.putString("thumbnail_url",game.thumbnail_url);
....
arrays.pushMap(map);
}
callback.invoke(arrays);
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…