Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

steelkiwi/ErrorParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

9 Commits

Repository files navigation

ErrorParser

Simple JSON parser for Android

Usage

Parser removes all nesting and empty objects from JSON, so you can easy get your object by key or position. Class will help you to get object from JSON with different variants.

Example of JSON: we'll call it myJson

{
 "field1": ["error1", []],
 "field2": ["error3", "error4"],
 "nested_fields": [
 {
 "field3": ["error5", "error6"],
 "field4": ["error7", "error8"],
 "non_fields_error": [[], "error10"]
 }
 ],
 "non_fields_error1": ["error11", "error12"]
}

Parser.simpleParsing(myJson)

String simpleParsing(String stringJson) {
 //will return "field1 - error1"
}

Parser.simpleParsing(myJson, "field1")

String simpleParsing(String stringJson, String exceptKey) {
 //will return "error1"
}

Parser.getMessageByPosition(myJson, 1, 1)

String getMessageByPosition(String source, int keyPosition, int messagePosition) {
 //will return "error4"
}

Parser.getMessageByPosition(myJson, "field4", 0)

String getMessageByPosition(String source, String key, int messagePosition) {
 //will return "error7"
}

Parser.getKeyWithMessageByPosition(myJson, 3, 1)

String getKeyWithMessageByPosition(String source, int keyPosition, int messagePosition) {
 //will return "field3 - error6"
}

Parser.getKeyWithMessageByPosition(myJson, "non_fields_error1", 1)

String getKeyWithMessageByPosition(String source, String key, int messagePosition) {
 //will return "non_fields_error1 - "error12""
}

Parser.getMessageByKey(myJson, "non_fields_error")

String getMessageByKey(String source, String key) {
 //will return "error10"
}

Parser.getMessageByKey(myJson, "non_fields_error1", 0)

String getMessageByKey(String source, String key, int messagePosition) {
 //will return "error11"
}

Parser.getMessageByKeyPosition(myJson, 1)

String getMessageByKeyPosition(String source, int keyPosition) {
 //will return "error3, error4"
}

Parser.getClearedJson(myJson)

String getClearedJson(String source) {
 //will return your string JSON without nesting and empty objects
}

License


Copyright 2017 SteelKiwi Inc, steelkiwi.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
 
 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Releases

No releases published

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /