Home > Java > javaTutorial > body text

What is the importance of JSONTokener in Java?

PHPz
Release: 2023-09-07 08:49:06
forward
1392 people have browsed it

What is the importance of JSONTokener in Java?

#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

Grammar

<strong>public class JSONTokener extends java.lang.Object</strong>
Copy after login

Example

is:

Example

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>(&#39;i&#39;);
      System.out.println("next character: " + c);
      System.out.println("has more tokens: " + b);
      System.out.println("next to i: " + s);
   }
}
Copy after login

Output

<strong>next character: T
has more tokens: true
next to i: Technology": "Java", "locat</strong>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template