http中requestbody参数json多层级问题

使用fastjson进行封装:

        Map map = new HashMap<>();
		map.put("timestamp", timestamp.toString());
		map.put("item_type", 1001);
		map.put("item_id", "xxxx");
		map.put("title", "xxxx");
		map.put("manual_category", "4");
		map.put("source", "xx");

		map.put("publish_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(timestamp)));

		JSONArray jsonArray=new JSONArray();
		int i =1;
		for (String url : urlList) {
			JSONObject videoObject = new JSONObject();
			videoObject.put("url",url);
			videoObject.put("title","xxxx");
			videoObject.put("format","mp4");
			videoObject.put("size",39400000);
			videoObject.put("duration",153);
			videoObject.put("item_id","100000"+i);
			videoObject.put("sn",i);
			i++;
			jsonArray.add(videoObject);
		}
		map.put("videos", jsonArray.toArray());

转json字符串:

String jsonString = JSON.toJSONString(map);

 

你可能感兴趣的:(工具类)