[英]How do you store arrays into a JSON object?
I have a the following objects: 我有以下对象:
server
: a string server
:字符串 products
: will be arrays within the server products
:将是服务器内的数组 productProperties
: will be an array within a product productProperties
:将是产品内的数组 Is the following a correct way to store the value in a JSON format? 以下是将值存储为JSON格式的正确方法吗?
JSONOBJECT jmap = new JSONOBJECT();
jsonArray jproduct = new jsonArray ();
jsonArray jproductsProperty1 = new jsonArray ();
jproductsProperty1 .put("P1");
jproductsProperty1 .put("P2");
jsonArray jproductsProperty2 = new jsonArray ();
jproductsProperty2 .put("Q1");
jproductsProperty2 .put("Q2");
jproduct.put(jproductsProperty1);
jproduct.put(jproductsProperty2);
jmap.put(server,jproduct);
out.print(jmap.toString());
first argument its just a key and second its your object could be a collection like a array 第一个参数只是一个键,第二个参数您的对象可能是像数组这样的集合
JSONOBJECT jmap = new JSONOBJECT();
jsonArray jproductsProperty1 = new jsonArray ();
jproductsProperty1.put("P1");
jproductsProperty1.put("P2");
jsonArray jproductsProperty2 = new jsonArray ();
jproductsProperty2.put("Q1");
jproductsProperty2.put("Q2");
jmap.put("jproductsProperty1", jproductsProperty1 );
jmap.put("jproductsProperty2", jproductsProperty2 );
okay i think i need to use two maps here .....like this 好吧,我想我需要在这里使用两张地图.....像这样
JSONObject jmap1 = new JSONObject();
JSONObject jmap2 = new JSONObject();
JSONArray jproduct = new JSONArray();
JSONArray jproductsProperty1 = new JSONArray();
jproductsProperty1 .put("P1");
jproductsProperty1 .put("P2");
JSONArray jproductsProperty2 = new JSONArray();
jproductsProperty2 .put("Q1");
jproductsProperty2 .put("Q2");
jproduct.put(jproductsProperty1);
jproduct.put(jproductsProperty2);
jmap2.put("jproductsProperty1", jproductsProperty1 );
jmap2.put("jproductsProperty2", jproductsProperty2 );
jmap1.put("A",jmap2);
System.out.println(jmap1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.