一、前言
通过java代码对JSON字符串平均分割后,存入不同oracle数据库varchar2(如长度2000)字段中,具体分割代码示例如下
import java.util.*;@b@@b@public class JsonSplitUtil {@b@ @b@ public static List<String> StringSplit() {@b@ @b@ int packetNum = 3;//分成几组 @b@ String str = "{\"aaa\":\"111\",\"bbb\":\"222\",\"ccc\":\"333\",\"ddd\":{\"d1\":\"44-1\",\"d2\":\"44-2\"}}";//要分组的字符串 @b@ List<String> list =new ArrayList<String>(); @b@ int packetLength = str.length()/packetNum; @b@ for (int i = 0; i < packetNum-1; i++) { @b@ list.add(str.substring(i*packetLength, i*packetLength+packetLength));@b@ } @b@ list.add(str.substring((packetNum-1)*packetLength, str.length())); @b@ return list;@b@ @b@ } @b@@b@ @b@ public static void main(String[] args) { @b@ System.out.println(StringSplit().get(0));@b@ System.out.println(StringSplit().get(1));@b@ System.out.println(StringSplit().get(2));@b@ }@b@ @b@@b@}
控制台运行结果
{"aaa":"111","bbb":"222@b@","ccc":"333","ddd":{"d@b@1":"44-1","d2":"44-2"}}