Home  >  Q&A  >  body text

java - json数据怎么按照固定顺序输出呢?

这是我想要的结果:["id":"1","text":"哈哈","children":[{"id":"1","text":"01"},{ "id":"2","text":"02" },{"id":"3","text":"03" }]]

但是输出是这样的["children":[{"id":"1","text":"01"},{ "id":"2","text":"02" },{ "id":"3","text":"03" }] ,"id":"1","text":"哈哈"]

PHP中文网PHP中文网2741 days ago494

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:28:33

    There is no difference between the two data. If you want to observe, you can just drag the columns into the order you like in the database. How the client puts them has nothing to do with the order.
    If you must change the order from the second to the first, you probably have to change the field names.
    aid, btext and children should be your order. But with this change, are you sure your boss won't hit you?

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:28:33

    JSON data cannot be output in the order you specify, because you did not tell the JSON parser to output it in that order. If you have to output in order, you can directly write a program to implement it.

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:28:33

    The json format output is not sorted according to the dictionary. You can output the first type in json, JSON.stringify(Object, function, number), you can change the output result. You may not know JSON.stingify()

    reply
    0
  • 阿神

    阿神2017-04-18 10:28:33

    According to the standard, JSON is unordered (KEY natural order)

    Chrome and Firefox both follow this standard, so c will definitely be ranked in front of d

    reply
    0
  • 阿神

    阿神2017-04-18 10:28:33

    What does the order matter? It is in the form of key value. Can't you just get it directly when you use it?

    reply
    0
  • Cancelreply