#The JSONTokener class allows applications to break strings into tokens. It can be used by the JSONObject and JSONArray constructors to parse JSON source strings. Several important methods of the JSONTokener class include back() - Move the cursor one position backward, more() - Return true if the token has elements, otherwise return false, next() - Returns the next character at the current position, nextTo(character) - Returns the string before matching the given character. The Chinese translation of
<strong>public class JSONTokener extends java.lang.Object</strong>
import java.io.*; import org.json.*; public class JSONTokenerTest { public static void main(String args[]) throws JSONException, Exception { String jsonStr = "{" + " \"Technology\": \"Java\", "+ " \"location\": [ Madhapur, Hyderabad ] " + "}"; <strong>JSONTokener </strong>jsonToken = new <strong>JSONTokener(jsonStr)</strong>; jsonToken.next(); jsonToken.next(); jsonToken.next(); jsonToken.next(); char c = jsonToken.<strong>next()</strong>; jsonToken.<strong>back()</strong>; boolean b = jsonToken.<strong>more()</strong>; String s = jsonToken.<strong>nextTo</strong>('i'); System.out.println("next character: " + c); System.out.println("has more tokens: " + b); System.out.println("next to i: " + s); } }
<strong>next character: T has more tokens: true next to i: Technology": "Java", "locat</strong>
The above is the detailed content of What is the importance of JSONTokener in Java?. For more information, please follow other related articles on the PHP Chinese website!