Home  >  Article  >  Web Front-end  >  About key-value data parsing and sorting in JsonObject (detailed tutorial)

About key-value data parsing and sorting in JsonObject (detailed tutorial)

亚连
亚连Original
2018-06-22 15:32:362767browse

The editor below will share with you an article about the key-value data parsing and sorting problem in JsonObject. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor and take a look.

1. The data in JsonObject is in key-value form. The key is obtained through the keys method of JsonObject. The iterator is unordered, if you want to achieve sorting, you can currently only install a layer of processing (the method comes from Stack Overflow, thank you master) and put key-vlaue into ThreeMap sorting. The default sorting rule is alphabetical order, which can be modified by customizing the Comparator.

iteratorKeys = object.keys();//得到所有title 
  SortedMap map = new TreeMap(); 
  while (iteratorKeys.hasNext()) { 
      String key = iteratorKeys.next().toString(); 
      String vlaue = object.optString(key); 
      map.put(key, vlaue); 
  } 
  itemData = new LinkedList(map.values());

2. The above cannot be sorted in the order of the returned results, so the JsonObject key can be sorted by adding a, b, c, etc. in front of the key.

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to implement a web version of the calculator in JS

How to remove the # sign in the url in Angular2 ( Detailed tutorial)

How to use the mobile component library in Vue.js (Detailed tutorial)

Related classes and constructors in Javascript , How to use factory functions

How to use vuex to implement menu management

Detailed interpretation of the new features of Angular5.1

How to implement gulp packaging using nodejs

How to use keep-alive in vue2

About jquery in webpack Plug-in environment configuration (detailed tutorial)

How to develop a tree component using Vue

How to develop a Sudoku game using vue

Detailed interpretation of webpack3 compilation compatible with IE8 (detailed tutorial)

How to use node to implement the rename file function

How to convert bool value in js?

The above is the detailed content of About key-value data parsing and sorting in JsonObject (detailed tutorial). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn