java - json数据怎么按照固定顺序输出呢?
PHP中文网
PHP中文网 2017-04-18 10:26:33
0
5
488

这是我想要的结果:["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中文网

认证高级PHP讲师

reply all(5)
洪涛

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?

刘奇

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.

巴扎黑

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()

阿神

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

阿神

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!