5:16 pm - Monday April 24, 2017

JSON Tokener With JAVA

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

JSONTokener:

JSONTokener class allows an application to break a string into tokens.

Methods:

next – This method returns a character next to current position.
back – It moves cursor one position back.
more – It returns true if the token has element. Else returns false.
nextTo(character) – It returns a string until the given character matches.

Project Structure:

JARFiles: 

 

 

 

JTokener.java:

package com.candidjava;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;

import org.json.*;

;

public class JTokener {
	public static void main(String args[]) throws JSONException, Exception {
		String json = "{" + "  \"Course\": \"Java\", "
				+ "  \"location\": [ chrompete, chennai ] " + "}";

		JSONTokener token = new JSONTokener(json);
		token.next();
		token.next();
		token.next();
		token.next();

		char c = token.next();

		token.back();
		boolean b = token.more();
		String s1 = token.nextTo('i');

		System.out.println("next character: " + c);
		System.out.println("has more tokens: " + b);
		System.out.println("next to i: " + s1);

	}
}

Output:
next character: C
has more tokens: true
next to i: Course”: “Java”, “locat

DOWNLOAD+SOURCECODE

Filed in: Z-A JSON codes

Comments are closed.