Skip to content

Instantly share code, notes, and snippets.

@IPRIT
Created March 25, 2015 18:10
Show Gist options
  • Save IPRIT/34193b6218201bb9d582 to your computer and use it in GitHub Desktop.
Save IPRIT/34193b6218201bb9d582 to your computer and use it in GitHub Desktop.
Example ResponseParser
package ru.twosphere.android.misisbooks;
import android.util.Log;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
/**
* Created by Александр on 31.01.2015.
*/
public class MisisBooksDataParser {
private String apiResponse;
public Edition[] getEditionsFromResponse(String apiResponseJsonStr)
throws JSONException {
apiResponse = apiResponseJsonStr;
final String OWN_RESPONSE = "response";
final String OWN_ITEMS = "items";
JSONObject responseJsonObject = new JSONObject(apiResponseJsonStr);
JSONArray editionsArray = responseJsonObject.getJSONObject(OWN_RESPONSE).getJSONArray(OWN_ITEMS);
Log.d("MISIS Books parser", String.valueOf(editionsArray.length()));
Edition[] mArr = new Edition[editionsArray.length()];
for (int i = 0; i < editionsArray.length(); i++) {
mArr[i] = new Edition(editionsArray.getJSONObject(i));
}
return mArr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment