Android JsonReader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android JsonReader class.

This code example shows how to use the following methods:beginArray, close, endArray, hasNext, nextString
        String jsonText = JavaScriptUtils.executeJavaScriptAndWaitForResult(
                view, viewClient, sb.toString());
        Assert.assertFalse("Failed to retrieve contents for " + nodeId,
                jsonText.trim().equalsIgnoreCase("null"));
 
        JsonReader jsonReader = new JsonReader(new StringReader(jsonText));
        String value = null;
        try { 
            jsonReader.beginArray();
            if (jsonReader.hasNext()) value = jsonReader.nextString();
            jsonReader.endArray();
            Assert.assertNotNull("Invalid contents returned.", value);
 
            jsonReader.close();
        } catch (IOException exception) {
            Assert.fail("Failed to evaluate JavaScript: " + jsonText + "\n" + exception);
        } 
        return value;
    } 
 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:beginObject, endObject, setLenient
	} 
 
	private boolean processInput(InputStream in) {
		JsonReader jr;
		try { 
			jr = new JsonReader(new BufferedReader(new InputStreamReader(in,
					"UTF-8"))); 
 
			jr.setLenient(true);
			jr.beginObject();
 
			/* Read ReturnCode */ 
			Pair<String, Boolean> pair = AdminHelper
					.handleResponse(JsonCustomReader.readJSONRetCode(jr, in));
 
			if (!pair.getSecond()) {
				errorMessage = pair.getFirst();
				return false; 
			} 
		 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:beginObject, endObject, setLenient
	} 
	 
	private boolean processInput(InputStream in){
		JsonReader jr;
		try { 
			jr = new JsonReader(new BufferedReader(new InputStreamReader(
					in, "UTF-8")));
 
			jr.setLenient(true);
			jr.beginObject();
 
			/* Read ReturnCode */ 
			Pair<String, Boolean> pair = AdminHelper
					.handleResponse(JsonCustomReader 
							.readJSONRetCode(jr, in));
			 
			if (!pair.getSecond()) {
				errorMessage = pair.getFirst();
				Log.v(TAG, "No Details found.");
				return false;  

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:beginObject, setLenient
		 
		private boolean processInput(InputStream in) {
			 
			JsonReader jr;
			try { 
				jr = new JsonReader(new BufferedReader(new InputStreamReader(
						in, "UTF-8")));
 
				jr.setLenient(true);
				jr.beginObject();
 
				/* Read ReturnCode */ 
				Pair<String, Boolean> pair = AdminHelper
						.handleResponse(JsonCustomReader 
								.readJSONRetCode(jr, in));
 
				errorMessage = pair.getFirst();
				return pair.getSecond();
				 
			} catch (UnsupportedEncodingException e) {
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
 
	public JsonReader nodeGet(int nid, String fields)
			throws ServiceNotAvailableException, ClientProtocolException, 
			IOException { 
		String uri = mENDPOIN + "node/" + nid;
		JsonReader jsr = new JsonReader(callGet(uri));
		return jsr;
	} 
 
	public JsonReader taxonomyVocabGetTree(int vid)
			throws ServiceNotAvailableException, ClientProtocolException, 
			IOException { 
		return taxonomyVocabGetTree(vid, 0, 0);
	} 
 
	public JsonReader taxonomyVocabGetTree(int vid, int parent, int maxdepth)
			throws ServiceNotAvailableException, ClientProtocolException, 
			IOException { 
		String uri = mENDPOIN + "taxonomy_vocabulary/getTree";
		int size = 2;
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:peek, skipValue
 
    // TODO: Create other safe read methods and use them. 
 
    protected static String readString(JsonReader reader, String nullValue)
            throws IOException { 
        if (reader.peek() == JsonToken.NULL) {
            reader.skipValue();
            return nullValue;
        } else { 
            return reader.nextString().trim();
        } 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close
			HttpURLConnection httpConnection = (HttpURLConnection) connection;
			int responseCode = httpConnection.getResponseCode();
 
			if (responseCode == HttpURLConnection.HTTP_OK) {
				InputStream in = httpConnection.getInputStream();
				JsonReader reader = new JsonReader(new InputStreamReader(in,
						"UTF-8")); 
				try { 
					// Clear the old earthquakes 
					earthquakes.clear();
					readEarthquakes(reader);
				} finally { 
					reader.close();
				} 
 
			} 
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:nextName
			//make url for twitter api 
			URL url = new URL("https://api.twitter.com/1/statuses/user_timeline.xml?screen_name=giddygoatupdate&count=1");
			//make input stream reader 
			Reader tweetReader = new InputStreamReader(url.openStream());
			//make json reader 
			JsonReader tweetJSONReader = new JsonReader(tweetReader); 
			//get status 
			String keyFromReader = tweetJSONReader.nextName();//get key for pair
			 
			//check key for match with status 
			if (keyFromReader.equals("status")) {
				//get the value for that key 
				 
			} 
			 
		} catch (MalformedURLException e) {
			Log.d("TwiterFeed", e.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block 
			Log.d("TwiterFeed", e.toString());
10
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:nextString
        setFile(new File(workingDir, filename));
    } 
 
    public void readField(JsonReader reader, String nameTok) throws IOException {
        if (TextUtils.equals(nameTok, "name")) {
            name = reader.nextString();
        } else if (TextUtils.equals(nameTok, "path")) {
            filename = reader.nextString();
        } 
    } 
 
    public void setFile(File file) {
        this.file = file;
        filesize = file.length();
        filename = file.getName();
    } 
} 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:
    protected JsonReader fetchJson(HttpsURLConnection connection) throws IOException {
        int resp = connection.getResponseCode();
        System.err.println("Response code: " + resp);
 
        InputStream s = connection.getInputStream();
        return new JsonReader(new InputStreamReader(s));
    } 
 
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    List<Job> getJobs(int limit) throws IOException {
        List<Job> jobs = new LinkedList<Job>();
        String args = "full=true";
 
        if (limit > 0) {
            args += "&limit=" + limit;
        } 
 
        HttpsURLConnection conn = this.buildConnection("GET", this.handle + "/jobs", args);
        JsonReader reader = this.fetchJson(conn);
 
3
CodeRank
Experience pair programming with AI  Get Codota for Java

Related Android JsonReader Questions & Answers:

See Code Examples for Android JsonReader Methods: