alibaba / alibaba/fastjson2

[BUG] 字符串转json对象,无法输出期待结果

Open
#3,167 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 问题描述
*简要描述您碰到的问题。*

### 环境信息
*请填写以下信息:*

- OS信息: win10
- JDK信息:JDK17
- 版本信息:Fastjson2 2.0.x43

### 重现步骤
String testStr = "{en:{\"SAVE\":\"save\",\"EMAIL\":\"E-MAIL\"}}";
JSONObject jsonObject = new JSONObject();
jsonObject.put("Il8N_SCRIPT", testStr);
System.out.println(jsonObject);
输出结果:{"Il8N_SCRIPT":"{en:{\"SAVE\":\"save\",\"EMAIL\":\"E-MAIL\"}}"}
```

### 期待的正确结果
期望输出结果:{"Il8N_SCRIPT":{"en":{"SAVE":"save","EMAIL":"E-MAIL"}}}

请问我该如何做才能输出期望结果?

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the supplied Java snippet, then inspect the JSONObject.put call and the related JSON parsing or serialization behavior. Done should establish whether the reported nested-object output is supported and, if so, produce the expected JSON; otherwise, clarify the required usage or documented limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.