1010011010
V2EX  ›  问与答

Java 如何 把 对象 转换成 json

  •  
  •   1010011010 · Apr 27, 2017 · 5742 views
    This topic created in 3479 days ago, the information mentioned may be changed or developed.

    用模板引擎 freemarker,输出对象能自动转成 json,但是为什么没有双引号!?

    像这样:

    [{aa:02, bb:BBB}]
    

    明明已经很接近了,为什么。。

    16 replies  •  2017-04-27 19:04:49 +08:00
    mortonnex
    mortonnex
    Apr 27, 2017
    1
    有双引号的是 string...

    对象--->json,用阿里的 fastjson
    1010011010
    1010011010
    OP
    Apr 27, 2017
    2
    @mortonnex #1
    "有双引号的是 string" 是什么意思?
    zhihaofans
    zhihaofans
    Apr 27, 2017 via iPhone
    3
    @1010011010 BBB 是个变量
    xmh51
    xmh51
    Apr 27, 2017
    4
    很好奇,为什么不用成熟的 json 框架? 是有限制吗?
    colincat
    colincat
    Apr 27, 2017 via iPhone
    5
    Freemarker 输出的不是 json 是对象 toString()之后出来的值吧
    shalk
    shalk
    Apr 27, 2017
    6
    gson, org.json 随便用一个库转; 最后 toString()
    xiaqinglin
    xiaqinglin
    Apr 27, 2017
    7
    用 gson 吧
    sagaxu
    sagaxu
    Apr 27, 2017
    8
    jackson 和 gson 都好,不要用 fastjson
    p0xiao
    p0xiao
    Apr 27, 2017
    9
    @sagaxu 为什么啊?
    1010011010
    1010011010
    OP
    Apr 27, 2017
    10
    @zhihaofans #3

    我是说 freemarker 输出的那个奇怪格式,键值都不加引号。值是字符串的
    sagaxu
    sagaxu
    Apr 27, 2017
    11
    @p0xiao 优点没有,缺点不少
    chocotan
    chocotan
    Apr 27, 2017
    12
    @1010011010 你自己都说了输出对象了啊....又不是输出 json 字符串
    bigpigeon
    bigpigeon
    Apr 27, 2017
    14
    JSON.stringify
    DJBird
    DJBird
    Apr 27, 2017 via iPhone
    15
    杰克森好用
    stcasshern
    stcasshern
    Apr 27, 2017
    16
    那我以后还是用 jackson 好了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3440 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 00:46 · PVG 08:46 · LAX 16:46 · JFK 19:46
    ♥ Do have faith in what you're doing.