com.koushikdutta.async.parser.JSONArrayParser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of androidasync Show documentation
Show all versions of androidasync Show documentation
Asynchronous socket, http(s) (client+server) and websocket library for android. Based on nio, not threads.
package com.koushikdutta.async.parser;
import com.koushikdutta.async.DataEmitter;
import com.koushikdutta.async.DataSink;
import com.koushikdutta.async.callback.CompletedCallback;
import com.koushikdutta.async.future.Future;
import com.koushikdutta.async.future.TransformFuture;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Created by koush on 5/27/13.
*/
public class JSONArrayParser implements AsyncParser {
@Override
public Future parse(DataEmitter emitter) {
return new StringParser().parse(emitter)
.then(new TransformFuture() {
@Override
protected void transform(String result) throws Exception {
setComplete(new JSONArray(result));
}
});
}
@Override
public void write(DataSink sink, JSONArray value, CompletedCallback completed) {
new StringParser().write(sink, value.toString(), completed);
}
}