Git Product home page Git Product logo

Comments (4)

yanxutao89 avatar yanxutao89 commented on June 15, 2024

能否提供下简单示例?

from fastjson2.

Apyz avatar Apyz commented on June 15, 2024

能否提供下简单示例?

老哥,找到问题了。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.

wenshao avatar wenshao commented on June 15, 2024

这样全局配置:

JSON.config(JSONReader.Feature. SupportSmartMatch);

from fastjson2.

wenshao avatar wenshao commented on June 15, 2024

fastjson 1.x缺省SupportSmartMatch有些场景符合客户的需求,有些场景则不是,收到了很多反馈和答疑。于是在2.x中就不是缺省打开了。

from fastjson2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.