alibaba / alibaba/fastjson2

[QUESTION]是否支持json字符串中嵌套json字符串的解析

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

Description

### 请描述您的问题
有一个json字符串
`{"address":"{\"province\":\"浙江省\",\"city\":\"杭州市\"}","name":"zhangsan"}`
能不能转换成如下类型的对象
`public class Bean {

private String name;

private Address address;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public Address getAddress() {
return address;
}

public void setAddress(Address address) {
this.address = address;
}

public static class Address{

private String province;

private String city;

public String getProvince() {
return province;
}

public void setProvince(String province) {
this.province = province;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}
}
}`

使用
`JSONObject.parseObject("{\"address\":\"{\\\"province\\\":\\\"浙江省\\\",\\\"city\\\":\\\"杭州市\\\"}\",\"name\":\"zhangsan\"}", Entity.class);`
解析会报错,有什么特性配置项可以支持吗

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the nested JSON-string case through JSONObject.parseObject(..., Entity.class), using the Bean and Address shapes shown in the issue. Determine whether an existing configuration or supported conversion path applies; done means the behavior and any required change or documentation are clearly established.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.