Skip to content

Commit

Permalink
fix target is replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycodeboy committed Nov 14, 2020
1 parent 19fbed6 commit 7e7c666
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ HiJson is a lightweight JSON parsing library that can be used for HarmonyOS, And
>Gradle
```
implementation 'org.devio.hi.json:hijson:0.0.5'
implementation 'org.devio.hi.json:hijson:1.0.0'
```

>Maven
Expand All @@ -35,7 +35,7 @@ implementation 'org.devio.hi.json:hijson:0.0.5'
<dependency>
<groupId>org.devio.hi.json</groupId>
<artifactId>hijson</artifactId>
<version>0.0.5</version>
<version>1.0.0</version>
</dependency>
```

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ bintray {
vcsUrl = "https://github.com/crazycodeboy/hijson.git"
issueTrackerUrl = "https://github.com/crazycodeboy/hijson/issue"
version {
name = '0.0.5'
desc = "hijson 0.0.5 final"
name = '1.0.0'
desc = "hijson 1.0.0 final"
released = new Date()
vcsTag = '0.0.5'
vcsTag = '1.0.0'
}
}
publications = ['MyPublication']
Expand All @@ -58,7 +58,7 @@ publishing {
artifact(javadocJar)
groupId "org.devio.hi.json"
artifactId 'hijson'
version '0.0.5'
version '1.0.0'
}
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/devio/hi/json/HiJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public HiJson(JSONObject jsonObject) {
this.target = jsonObject;
}

public HiJson(JSONArray jsonArray) {
this.target = jsonArray;
}

public <T> T value() {
try {
return (T) target;
Expand All @@ -46,7 +50,12 @@ public <T> T value(String name) {
public HiJson get(String name) {
try {
if (target instanceof JSONObject) {
target = ((JSONObject) target).get(name);
Object o = ((JSONObject) target).get(name);
if (o instanceof JSONObject) {
return new HiJson((JSONObject) o);
} else if (o instanceof JSONArray) {
return new HiJson((JSONArray) o);
}
}
} catch (JSONException e) {
e.printStackTrace();
Expand All @@ -57,7 +66,12 @@ public HiJson get(String name) {
public HiJson get(int index) {
try {
if (target instanceof JSONArray) {
target = ((JSONArray) target).get(index);
Object o = ((JSONArray) target).get(index);
if (o instanceof JSONObject) {
return new HiJson((JSONObject) o);
} else if (o instanceof JSONArray) {
return new HiJson((JSONArray) o);
}
}
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -67,6 +81,7 @@ public HiJson get(int index) {

/**
* 获取JSONArray数组长度
*
* @return
*/
public int count() {
Expand Down

0 comments on commit 7e7c666

Please sign in to comment.