首发于 JAVA计算

解析多层 json 存入 CSV 文件

问题

I’m trying to export JSON to a csv file, but I can’t seem to find a step by step tutorial. I’m wondering if anyone can help me?

I have parsed my JSON file using the approach discribed in this link .

It works now, but I still need to figure out how to export the parsed data into a CSV file..

You can find in the link below the JSON file I parsed, I just have to figure out how to export:

“attributeName”: “Description”,  
“attributeValue”: ""  
“attributeName”: “Functional Area”,  
“attributeValue”: “TECH”
public static void main(String[] args){
  String json=“{\“content\”: [  {\“a\”:{ \“b\” : \“abcd\”, \“c\” : \“bcd\”},\“ab\” : \“123\”,\“abc\”:{\“id\” : \“12345\”, \“name\” : \“abcde\”},\“cd\”: \“afsf\”},{\“a\”:{\“b\” : \“abcd\”,  \“c\” : \“bcd\”},\“ab\” : \“123\”,\“abc\”:{\“id\” : \“12346\”,\“name\” : \“abcde\”},\“cd\”: \“afsf\”}]}”;
        JSONObject jsonObject = new JSONObject(json);
        JSONArray jsonArray = jsonObject.getJSONArray(“content”);
        for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject objects = jsonArray.getJSONObject(i);
                    String[] elementNames = JSONObject.getNames(objects);
                       for (String elementName : elementNames)
                           if(elementName.equalsIgnoreCase(“abc”)){
                           JSONObject value = objects.getJSONObject(elementName);
                           String[] elementList = JSONObject.getNames(value);
                            for(String j:elementList){
                                if(j.equalsIgnoreCase(“id”)){
                                System.out.println(value.getString(“id”));