Skip to content

Commit 7e7c666

Browse files
committed
fix target is replaced
1 parent 19fbed6 commit 7e7c666

3 files changed

Lines changed: 23 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ HiJson is a lightweight JSON parsing library that can be used for HarmonyOS, And
2626
>Gradle
2727
2828
```
29-
implementation 'org.devio.hi.json:hijson:0.0.5'
29+
implementation 'org.devio.hi.json:hijson:1.0.0'
3030
```
3131

3232
>Maven
@@ -35,7 +35,7 @@ implementation 'org.devio.hi.json:hijson:0.0.5'
3535
<dependency>
3636
<groupId>org.devio.hi.json</groupId>
3737
<artifactId>hijson</artifactId>
38-
<version>0.0.5</version>
38+
<version>1.0.0</version>
3939
</dependency>
4040
```
4141

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ bintray {
4242
vcsUrl = "https://github.com/crazycodeboy/hijson.git"
4343
issueTrackerUrl = "https://github.com/crazycodeboy/hijson/issue"
4444
version {
45-
name = '0.0.5'
46-
desc = "hijson 0.0.5 final"
45+
name = '1.0.0'
46+
desc = "hijson 1.0.0 final"
4747
released = new Date()
48-
vcsTag = '0.0.5'
48+
vcsTag = '1.0.0'
4949
}
5050
}
5151
publications = ['MyPublication']
@@ -58,7 +58,7 @@ publishing {
5858
artifact(javadocJar)
5959
groupId "org.devio.hi.json"
6060
artifactId 'hijson'
61-
version '0.0.5'
61+
version '1.0.0'
6262
}
6363
}
6464
}

src/main/java/org/devio/hi/json/HiJson.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ public HiJson(JSONObject jsonObject) {
2323
this.target = jsonObject;
2424
}
2525

26+
public HiJson(JSONArray jsonArray) {
27+
this.target = jsonArray;
28+
}
29+
2630
public <T> T value() {
2731
try {
2832
return (T) target;
@@ -46,7 +50,12 @@ public <T> T value(String name) {
4650
public HiJson get(String name) {
4751
try {
4852
if (target instanceof JSONObject) {
49-
target = ((JSONObject) target).get(name);
53+
Object o = ((JSONObject) target).get(name);
54+
if (o instanceof JSONObject) {
55+
return new HiJson((JSONObject) o);
56+
} else if (o instanceof JSONArray) {
57+
return new HiJson((JSONArray) o);
58+
}
5059
}
5160
} catch (JSONException e) {
5261
e.printStackTrace();
@@ -57,7 +66,12 @@ public HiJson get(String name) {
5766
public HiJson get(int index) {
5867
try {
5968
if (target instanceof JSONArray) {
60-
target = ((JSONArray) target).get(index);
69+
Object o = ((JSONArray) target).get(index);
70+
if (o instanceof JSONObject) {
71+
return new HiJson((JSONObject) o);
72+
} else if (o instanceof JSONArray) {
73+
return new HiJson((JSONArray) o);
74+
}
6175
}
6276
} catch (Exception e) {
6377
e.printStackTrace();
@@ -67,6 +81,7 @@ public HiJson get(int index) {
6781

6882
/**
6983
* 获取JSONArray数组长度
84+
*
7085
* @return
7186
*/
7287
public int count() {

0 commit comments

Comments
 (0)