Importance of a JSONTokener in Java?n

The JSONTokener class allows an application to break a string into tokens. It can be used by the JSONObject and JSONArray constructors to parse JSON source strings. A few important methods of JSONTokener class are back() - moves cursor one position back, more() - returns true if the token has element or else returns false, next() - returns a character next to current position and nextTo(character) - returns a string until the given character matches.


public class JSONTokener extends java.lang.Object


import org.json.*;
public class JSONTokenerTest {
   public static void main(String args[]) throws JSONException, Exception {
      String jsonStr = "{" + " \"Technology\": \"Java\", "+ " \"location\": [ Madhapur, Hyderabad ] " + "}";
      JSONTokener jsonToken = new JSONTokener(jsonStr);;;;;
      char c =;
      boolean b = jsonToken.more();
      String s = jsonToken.nextTo('i');
      System.out.println("next character: " + c);
      System.out.println("has more tokens: " + b);
      System.out.println("next to i: " + s);


next character: T
has more tokens: true
next to i: Technology": "Java", "locat