Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG][v2.0.2]JSON.parseArray解析有问题? #235

Closed
kervin521 opened this issue May 13, 2022 · 3 comments
Closed

[BUG][v2.0.2]JSON.parseArray解析有问题? #235

kervin521 opened this issue May 13, 2022 · 3 comments
Labels
question Further information is requested
Milestone

Comments

@kervin521
Copy link

kervin521 commented May 13, 2022

问题描述

简要描述您碰到的问题。
image
① 处多了右花括号
② 通过解析为对象集合List
③ 通过解析为对象集合过程正确,但解析结果为2个
④ 通过解析为json对象数组JSONArray
⑤ 通过解析为json对象数组过程异常

环境信息

请填写以下信息:

  • OS信息: [e.g.:Windows 10]
  • JDK信息: [e.g.:Openjdk 1.8.0_312]
  • 版本信息:[e.g.:Fastjson2 2.0.2]

重现步骤

如何操作可以重现该问题:

import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;

import lombok.Data;

public class JSONTest {
	@Data
	public static class TModal{
		private String namespace;
		private List<String> items;
	}
	public static void main(String[] args) {
		String json = "[{\r\n"
				+ "  \"namespace\":\"unit07\", \r\n"
				+ "  \"items\":[\"COUNTER13_14.AV\",\r\n"
				+ "  \"COUNTER13_15.AV\"]\r\n"
				+ "}\r\n"
				+ "}]";
		JSONArray arrays = JSON.parseArray(json);
		System.out.println(arrays.size());
		List<TModal> list = JSON.parseArray(json, TModal.class);
		System.out.println(list.size());
	}

}

期待的正确结果

对您期望发生的结果进行清晰简洁的描述。

### 两种方式结果能够一致
要么都解析失败,要么解析成功并且个数是1个

相关日志输出

请复制并粘贴任何相关的日志输出。

附加信息

如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。

@kervin521 kervin521 added the bug Something isn't working label May 13, 2022
wenshao added a commit that referenced this issue May 13, 2022
@wenshao
Copy link
Member

wenshao commented May 13, 2022

是你的json不符合格式,多了一个 '}',不过报错信息不够友好,这个后面会完善。

@wenshao wenshao added question Further information is requested and removed bug Something isn't working labels May 13, 2022
@wenshao wenshao closed this as completed May 13, 2022
@kervin521
Copy link
Author

@wenshao 那两种解析都应该报错吧,

@wenshao wenshao reopened this May 17, 2022
@wenshao wenshao modified the milestones: 2.0.4, 2.0.5 May 17, 2022
@wenshao
Copy link
Member

wenshao commented May 28, 2022

https://github.com/alibaba/fastjson2/releases/tag/2.0.5
问题已修复,请用新版本

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants