All Projects → amirdew → JSON

amirdew / JSON

Licence: MIT License
Simple and easy JSON parser, JSON generator, and data holder based on JSONArray and JSONObject for android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to JSON

Heyyoo
Heyyoo is a sample social media Android application 📱 built to demonstrate use of Modern Android development tools - (Kotlin, Coroutines, Architecture Components, MVVM, Room, Retrofit, Material Components).
Stars: ✭ 38 (-51.28%)
Mutual labels:  gson, android-application
Bfj
MOVED TO GITLAB
Stars: ✭ 164 (+110.26%)
Mutual labels:  json-data, json-serialization
Dowy
🎬Application that displays a list of Movies and Tv Series using Modern Android Application Development tools and API's
Stars: ✭ 29 (-62.82%)
Mutual labels:  gson, android-application
RNLauncher
A custom Android Launcher made with ReactNative
Stars: ✭ 89 (+14.1%)
Mutual labels:  android-application
FancyAboutPage-Android
Fancy About Page is a simple and lightweight library that helps you to create cool and beautiful about page for your apps without writing dozens of lines of code. It's a material-design about screen to use on your Android apps. A developer profile and application information easy to integrate.
Stars: ✭ 79 (+1.28%)
Mutual labels:  android-application
MrTranslator
📘MrTranslator-A Translation Android APP
Stars: ✭ 16 (-79.49%)
Mutual labels:  gson
ti5x android
TI-58C/TI-59 calculator emulator for Android
Stars: ✭ 17 (-78.21%)
Mutual labels:  android-application
Pictograph-Keyboard
Simple Emoji Keyboard application
Stars: ✭ 14 (-82.05%)
Mutual labels:  android-application
SignInSignupScreen-Android
SignIn and SignUp in android 😊😊😉
Stars: ✭ 51 (-34.62%)
Mutual labels:  android-application
hackathon-foodie
Foodie is a centralized food ordering app for restaurants near NIT Hamirpur.
Stars: ✭ 26 (-66.67%)
Mutual labels:  android-application
NewMessengerBot
a new Messenger Bot Application with Hilt + ViewModel + Fragment.
Stars: ✭ 15 (-80.77%)
Mutual labels:  android-application
FireFiles
Powerful Android File Manager for everything that runs on Android OS (Android TV, Android Watch, Mobile, etc)
Stars: ✭ 37 (-52.56%)
Mutual labels:  android-application
Meow
Yet another free and open source manga reader
Stars: ✭ 42 (-46.15%)
Mutual labels:  android-application
FaceRecognition With FaceNet Android
Face Recognition using the FaceNet model and MLKit on Android.
Stars: ✭ 113 (+44.87%)
Mutual labels:  android-application
JSONCustomLintr
Library to allow creation, running, and reporting of custom lint rules for JSON files
Stars: ✭ 19 (-75.64%)
Mutual labels:  json-data
UninstallSystemApps
Uninstall System Apps is a free app to remove system apps! You can join here!
Stars: ✭ 62 (-20.51%)
Mutual labels:  android-application
Android-Diagonal-Cut-View
learnyandroid.blogspot.com/2017/11/create-diagonal-cut-view-in-android.html
Stars: ✭ 14 (-82.05%)
Mutual labels:  android-application
SpeechToText
Speech To Text in Android
Stars: ✭ 53 (-32.05%)
Mutual labels:  android-application
AndroidBatteryStats
Displays all battery stats of an Android device using broadcast receiver.
Stars: ✭ 20 (-74.36%)
Mutual labels:  android-application
computeiro
Computer science courses, books and exams in your pocket. Built with Flutter and Free! ❤️
Stars: ✭ 27 (-65.38%)
Mutual labels:  android-application

JSON

Codacy Badge Android Arsenal

simple and easy json parser, json generator, and data holder based on JSONArray and JSONObject for android,
like SwiftyJSON but for android

Add to your project

To use JSON you must add it as a dependency in your Gradle build:

Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			...
			maven { url "https://jitpack.io" }
		}
	}

Step 2. Add the dependency

dependencies {
    compile 'com.github.amirdew:JSON:v1.0.0'
}

Usage - parse json

You can create JSON object from string and access data with key() and index() methods.

String simpleJsonString = "{\"id\":1,\"name\":\"A green door\",\"price\":12.5,\"tags\":[\"home\",\"green\"]}";

JSON json = new JSON(simpleJsonString);
        
//access data
String firstTag = json.key("tags").index(0).stringValue();
Double price = json.key("price").doubleValue();

products json:

[
  {
    "id": 2,
    "name": "An ice sculpture",
    "price": 12.50,
    "tags": ["cold", "ice"],
    "dimensions": {
      "length": 7.0,
      "width": 12.0,
      "height": 9.5
    },
    "warehouseLocation": {
      "latitude": -78.75,
      "longitude": 20.4
    }
  },
  {
    "id": 3,
    "name": "A blue mouse",
    "price": 25.50,
    "dimensions": {
      "length": 3.1,
      "width": 1.0,
      "height": 1.0
    },
    "warehouseLocation": {
      "latitude": 54.4,
      "longitude": -32.7
    }
  }
]

loop:

for(int i=0; i<products.count(); i++){
   
   json productInfo = products.index(i);
   String productName = productInfo.key("name").stringValue();
}

JSON is exception and null free, you can use key() and index() many times without worry about any exception.

 int someValue = products.index(8).key("someKey").index(1).key("someOther").intValue();
 //someValue = 0

check index or key is exist or is null:

 if( products.index(3).key("someKey").isNull() ){ 
    /*...*/ 
 }

if( products.index(1).key("someKey").exist() ){
   /*...*/ 
 }

Available methods - parse

Method Input type Return type Default Description
key() String JSON - if object is a dictionary return JSON object with input key
index() int JSON - if object is a array return JSON object with input index
stringValue() - String empty string ("") return .toString() of object
intValue() - int 0 return integer value if possible
longValue() - long 0 return long value if possible
doubleValue() - Double 0 return Double value if possible
booleanValue() - boolean false return true if object is kind of boolean and true or is kind of string and equal "true"
value() - Object - return related object
count() - int 0 if related object is a dictionary return number of keys, if related object is a array return length of array
isNull() - boolean - return true if related object is null
exist() - boolean - return true if related object with index or key exists
getJsonArray() - JSONArray null return related JSONArray
getJsonObject() - JSONObject null return related JSONObject

Usage - generate json, data holding

You can use JSON.dic() and JSON.array() static methods to generate json string or hold and pass data

  JSON generatedJsonObject = JSON.create(
                JSON.dic(
                        "someKey", "someValue",
                        "someArrayKey", JSON.array(
                                "first",
                                1,
                                2,
                                JSON.dic(
                                        "emptyArrayKey", JSON.array()
                                )
                        )
                )
        );
        
        
  String jsonString = generatedJsonObject.toString();

result:

{
  "someKey": "someValue",
  "someArrayKey": [
    "first",
    1,
    2,
    {
      "emptyArrayKey": []
    }
  ]
}

add, edit, remove:

note: now its work for first level only

  generatedJsonObject.addEditWithKey("someArrayKey","someOtherValue");

result:

{
  "someKey": "someValue",
  "someArrayKey": "someOtherValue"
}

Available methods - generate, edit, remove

Method Input type Description
add() Object if current related object is an array add object at end of array
remove() Object if current related object is an array and input object exist, remove it from array
addWithIndex() Object, int if current related object is an array replace input object with object for input index
removeWithIndex() int if current related object is an array remove object for input index
addEditWithKey() String, Object if current related object is a dictionary add input object with input key
removeWithKey() String if current related object is a dictionary remove object with input key
static create() Object create new instance of JSON with input object
static dic() Object... if number of input objects is even create JSONObject use even objects as key and odd obejcts as value
static array() Object... create JSONArray use input objects
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].