Comments (4)
能否提供下简单示例?
from fastjson2.
能否提供下简单示例?
老哥,找到问题了。fastjson1的时候,能自动解析首字母大写的key,我也没配置过。到了fastjson2各种问题都出来了,首字母大写的key全是null。特殊字符的key,getter 和 setter方法也得添加@JSONField名称映射,否则也全是null。fastjson1只需要在对象上添加@JSONField名称映射就能获取的。不过问题已经解决,也就不说什么了。我谈下解决方式吧。
String jsonBean = "{\"answer_count\":0,\"comment_count\":891,\"counters\":[{\"Count\":2084394,\"Name\":\"展现\"},{\"Count\":223516,\"Name\":\"阅读\"},{\"Count\":891,\"Name\":\"评论\"},{\"Count\":2902,\"Name\":\"点赞\"}],\"digg_count\":2902,\"go_detail_count\":223516,\"impression_count\":2084394,\"play_count\":0,\"repin_count\":0}";
// Feature.DisableFieldSmartMatch
JSON.config(JSONReader.Feature.SupportSmartMatch);
Result result = JSON.parseObject(jsonBean, Result.class);
Result.Counters counters = result.getCounters().get(0);
System.out.println("name:" + counters.getName());
System.out.println("name:" + counters.getCount());
JSON.config(JSONReader.Feature.SupportSmartMatch);
特性那里要配置支持智能匹配,否则获取的首字母大写的key全是null,也是简直了,这东西居然不是默认的,fastjson1的时候,这都不需要操心的,直接上,啥都能给匹配上。
from fastjson2.
这样全局配置:
JSON.config(JSONReader.Feature. SupportSmartMatch);
from fastjson2.
fastjson 1.x缺省SupportSmartMatch有些场景符合客户的需求,有些场景则不是,收到了很多反馈和答疑。于是在2.x中就不是缺省打开了。
from fastjson2.
Related Issues (20)
- [QUESTION]如何在自定义序列化时实现某条件满足时忽略该字段的序列化 HOT 3
- [BUG] Parcelable 序列化以后的类,转换成json格式,多了一个{"stability":0}}字段 HOT 2
- [FEATURE] 请问是否有考虑支持JSONQuery? HOT 1
- [FEATURE] 兼容jackson的序列化/反序列化注解 HOT 1
- [FEATURE] 不同类集合间的复制实现 HOT 1
- 后台返回出现JSON前边乱码请问怎么解决 HOT 5
- [BUG] 将localdatetime put到jsonobject,再次输出时候T不见了 HOT 2
- [BUG]JSON.isValid()方法抛出了异常 HOT 2
- [FEATURE] 自定义反序列化/序列化的时候, 可以通过@JSONField传递参数到ObjectReader的readObject方法?
- [BUG]反序列化报错 JSONException HOT 1
- [QUESTION] 从1.x升级后JSON.toJSON() 方法遇到的问题 HOT 1
- [BUG]JSONPath不支持中划线 HOT 7
- [BUG]枚举类型反序列化问题 HOT 1
- [BUG] 反序列化时JSONObject字段出现{"h":{***}}结构 HOT 6
- [BUG]Dubbo Tri协议调用序列化报错 HOT 7
- [BUG] wiki描述有误
- [BUG] 反序列化null的list报错 HOT 7
- [BUG] 版本2.0.46 引用类型、Boolean、Short 不支持JSONWriter.Feature.WriteNulls HOT 6
- 支持jsonschema数据的fake
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastjson2.