Is there any difference between '{' and '[' when formatting a JSON object?
4 Answers
Yep one {...} is used to define a single object, while the other [...] is used to define a sequence of either objects, values or lists ...
objects are defined as such {key:object or list or value , ...}
list ares nothing more than a sequence of either objects or lists or values, [objects or list or values, ... ]...
[{'value':1}, {'values':[1,2,3,3, {'a':'a', 'b':'b'}]}, 2, 3, 4]
1 Comment
imnhasan
It's perfect one.
package ravi.kumar;
import java.util.ArrayList;
import java.lang.Object;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class SetListClass {
public static void main(String[] args) {
SetListClass SetListClass = new SetListClass();
List<String> list = new ArrayList<String>();
list.add("country");
list.add("state");
list.add("distract");
list.add("country");
System.out.println(list);
System.out.println("----------------------------------------------");
SetListClass.getset();
System.out.println("----------------------------------------------");
SetListClass.getHashMap();
}
public void getset()
{
Set<String> set = new HashSet<String>();
set.add("country");
set.add("state");
set.add("distract");
set.add("country");
System.out.println(set);
System.out.println(set.remove("country"));
System.out.println("---------------------------------------------");
System.out.println(set);
}
public void getHashMap() {
HashMap<String, Object> hashmap = new HashMap<String, Object>();
hashmap.put("country", "india");
hashmap.put("state", "bihar");
hashmap.put("district", "buxar");
System.out.println(hashmap);
}
}
output
-------
[country, state, distract, country] ------array
----------------------------------------------
[state, distract, country] ----array
true
---------------------------------------------
[state, distract]
----------------------------------------------
{state=bihar, district=buxar, country=india} ---Object
1 Comment
Ravi Kumar
map contains key value pair, keys are nothing but set and values are nothing but list.