Git Product home page Git Product logo

jsonparser's Introduction

JsonParser

Json parsing tool can flexibly configure

License Download

Import

add to build.gradle,${latest.version} is Download

dependencies {
    compile 'com.blakequ.parser:parser:${latest.version}'
}

maven

<dependency>
  <groupId>com.blakequ.parser</groupId>
  <artifactId>parser</artifactId>
  <version>${latest.version}</version>
  <type>pom</type>
</dependency>

How to use

you can download example and study how to use

1. config json entity

Json:json_list.txt
{
    "entities": [
        {
            "createdTime": 1422347864000,
            "descript": "2",
            "index": 45,
            "id": 43,
            "isDeleted": false,
            "name": "患者端宣传广告01",
            "page": "2",
            "ids":9,
            "pic": "upload/pic/2015-03-12/20150312093910706.jpg"
        },
        {
            "descript": "恶趣味全文",
            "index": 10,
            "id": 48,
            "isDeleted": true,
            "name": "患者端宣传广告02",
            "page": "23",
            "pic": "upload/pic/2015-03-12/20150312093934988.jpg"
        }
    ],
    "status": "200"
}

Entity:
@JsonParserClass(parserRoot="entities")
public class UserEntity{
    //need not annotation if name is equal 
	private double index;//json is index, need not JsonParserField
	private int id;
	
	//you can set default value if field is null by invoke defaultValue
	@JsonParserField(defaultValue="1110")
	private Short ids;
	
	//you should set praser name if field is not same with json
	@JsonParserField(praserKey="createdTime", defaultValue="110")
	private long time;
	@JsonParserField(praserKey="descript")
	private String descripte;
	@JsonParserField(praserKey="isDeleted", defaultValue="1")
	private boolean isDelete;
	@JsonParserField(defaultValue="unknow")
	private String name;
	@JsonParserField(defaultValue="0")
	private Long page;
	@JsonParserField(defaultValue="")
	private String pic;
	
	public long getTime() {
		return time;
	}
	public void setTime(long time) {
		this.time = time;
	}
	public String getDescripte() {
		return descripte;
	}
	public void setDescripte(String descripte) {
		this.descripte = descripte;
	}
	public double getIndex() {
		return index;
	}
	public void setIndex(double index) {
		this.index = index;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public boolean isDelete() {
		return isDelete;
	}
	public void setDelete(boolean isDelete) {
		this.isDelete = isDelete;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Long getPage() {
		return page;
	}
	public void setPage(Long page) {
		this.page = page;
	}
	public String getPic() {
		return pic;
	}
	public void setPic(String pic) {
		this.pic = pic;
	}
	@Override
	public String toString() {
		return "UserEntity [time=" + time + ", descripte=" + descripte
				+ ", index=" + index + ", id=" + id + ", isDelete=" + isDelete
				+ ", name=" + name + ", page=" + page + ", pic=" + pic + ",ids="+ids+"]";
	}

}

==notice:if entity field is private, you should provide set and set method==

2. get parser result

String str2 = ResourceUtils.geFileFromAssets(this, "json_list.txt");
List<UserEntity> user = (List<UserEntity>) JsonParserUtils.initEntityParser(UserEntity.class, str2, true);

proguard

you should add bean to proguard file

-keep class com.example.data.model.UserEntity {*;}

screenshot

parser result:

link

jsonparser's People

Contributors

haodynasty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.