Git Product home page Git Product logo

parser's Introduction

Parser

JSON stands for JavaScript Object Notation. It is an independent data exchange format and is the best alternative for XML.

Android provides four different classes to manipulate JSON data.
These classes are JSONArray,JSONObject,JSONStringer and JSONTokenizer.
The first step is to identify the fields in the JSON data in which you are interested in.
For example in the JSON given below we interested in getting temperature only.

{
   "sys":
   {
      "country":"GB",
      "sunrise":1381107633,
      "sunset":1381149604
   },
   "weather":[
      {
         "id":711,
         "main":"Smoke",
         "description":"smoke",
         "icon":"50n"
      }
   ],
	
  "main":
   {
      "temp":304.15,
      "pressure":1009,
   }
}
Method Description
Array [] In a JSON file , square bracket [ represents a JSON array
Objects {} In a JSON file, curly bracket { represents a JSON object
Key A JSON object contains a key that is just a string. Pairs of key/value make up a JSON object
Value Each key has a value that could be string , integer or double e.t.c

JSON Parsing

For parsing a JSON object, we will create an object of class JSONObject and specify a string containing JSON data to it.

String in;
JSONObject reader = new JSONObject(in);

The last step is to parse the JSON. A JSON file consist of different object with different key/value pair e.t.c.
So JSONObject has a separate function for parsing each of the component of JSON file.

JSONObject sys  = reader.getJSONObject("sys");
country = sys.getString("country");
JSONObject main  = reader.getJSONObject("main");
temperature = main.getString("temp");

parser's People

Contributors

faramarzaf avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.