Sting数组或者list转为jsonArray

Gson gson =  new GsonBuilder().create();
                    if(mNode.getProperty(s).getValue() instanceof List){
                        List value = (List)mNode.getProperty(s).getValue();
                        final JsonArray array = gson.toJsonTree(value).getAsJsonArray();
                        propertyObject.add(s,array);
                    }else if(mNode.getProperty(s).getValue() instanceof String[]){
                        String[] value = (String[]) mNode.getProperty(s).getValue();
                        final JsonArray array = gson.toJsonTree(value).getAsJsonArray();
                        propertyObject.add(s,array);
                    } else if(mNode.getProperty(s).getValue() instanceof Object) {
                        String jsonStr = gson.toJson(mNode.getProperty(s).getValue());
                        JsonObject jsonObject = new JsonParser().parse(jsonStr).getAsJsonObject();
                        propertyObject.add(s,jsonObject);
                    }

你可能感兴趣的:(java)