bug fixed for issue #784

This commit is contained in:
wenshao
2016-08-24 10:03:58 +08:00
parent de86fd895c
commit 5503d4552b
2 changed files with 20 additions and 2 deletions
@@ -1110,7 +1110,7 @@ public class DefaultJSONParser implements Closeable {
}
try {
final boolean first_quote;
boolean first_quote;
char ch = lexer.ch;
if (ch != '"') {
if (ch == ']') {
@@ -1161,6 +1161,8 @@ public class DefaultJSONParser implements Closeable {
if (ch == '"') {
continue;
} else {
first_quote = false;
}
lexer.nextToken();
@@ -1,7 +1,23 @@
package com.alibaba.json.bvt.bug;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import junit.framework.TestCase;
import org.junit.Assert;
/**
* Created by wenshao on 16/8/24.
*/
public class Issue784 {
public class Issue784 extends TestCase {
public void test_for_issue() throws Exception {
String json = "[\"150\",\"change\",{\"timeStamp\":1471595047319,\"value\":\"\"},{\"attrs\":{\"value\":\"\"}}]";
JSONArray jsonArray = (JSONArray) JSON.parse(json);
Assert.assertEquals("150", jsonArray.get(0));
Assert.assertEquals("change", jsonArray.get(1));
Assert.assertEquals(1471595047319L, jsonArray.getJSONObject(2).get("timeStamp"));
Assert.assertEquals("", jsonArray.getJSONObject(2).get("value"));
Assert.assertEquals("", jsonArray.getJSONObject(3).getJSONObject("attrs").get("value"));
Assert.assertEquals(4, jsonArray.size());
}
}