Java到JSON格式

Java到JSON格式,java,json,Java,Json,这是我的示例应用程序,其结果如下: Array Values : arr[0][0] :6 arr[0][1] :0 arr[0][2] :0 arr[1][0] :0 arr[1][1] :0 arr[1][2] :0 String CSVFileToWrite = "../../MyCSVFile.csv";//file with .csv extension String colkeys = "categories,jan,oct,nov"; S

这是我的示例应用程序,其结果如下:

Array Values  : 
arr[0][0] :6
arr[0][1] :0 
arr[0][2] :0 
arr[1][0] :0 
arr[1][1] :0    
arr[1][2] :0
    String CSVFileToWrite = "../../MyCSVFile.csv";//file with .csv extension
    String colkeys = "categories,jan,oct,nov";
    String rowKeys = "row1,row2";
    String[] row = rowKeys.split(",");

    String[][] array = {{"250,340,456"}, {"123,567,789"}};
    System.out.print(array[0][0]);
    System.out.println("");
    System.out.print(array[1][0]);
    try {
        File file = new File(CSVFileToWrite);
        FileWriter fw1 = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fw1);

        int col=0;
        int row1=3;
        int i=0;
        String[][] arrayValues = new String[row1][1];
        arrayValues[0][0]=colkeys;
        for(int r=1; r < row1 ;r++) {
            arrayValues[r][col]=row[i] + "," + array[i][col];
            //System.out.println("ArrayValues["+r+"][" + col +"]" + arrayValues[r][col]);
            i++;
        }
        for(int r=0 ; r < row1 ;r++) {
            bw.write(arrayValues[r][col]);
            bw.newLine();
            bw.flush();
        }
        bw.close();
        System.out.println("File generated Successufully at location  "+ file.getAbsolutePath());
    } catch (IOException ex) {
    }
因为我有这个jQuery Highcharts:

chart = new Highcharts.Chart({
                              chart: {
                                renderTo: 'container',
                                defaultSeriesType: 'column'
                              },
                              title: {
                        text: document.chart.chartTitle.value
                              },                                            
                              series: [{
                                 name: 'USA',
                                 data: [50, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
                               }, {
                                 name: 'New York',
                                 data: [83.6, 78.8, 98.5, 93.4, 106.0, 84.5, 105.0, 104.3, 91.2, 83.5, 106.6, 92.3]
                               }, {
                                 name: 'London',
                                 data: [48.9, 38.8, 39.3, 41.4, 47.0, 48.3, 59.0, 59.6, 52.4, 65.2, 59.3, 51.2]
                               }, {
                                 name: 'Berlin',
                                 data: [42.4, 33.2, 34.5, 39.7, 52.6, 75.5, 57.4, 60.4, 47.6, 39.1, 46.8, 51.1]
                              }]
                       });
我必须传递ro_count、ro_free_count等,而不是“series”中的“name”和“arr[I][j]”值,而不是“data”位置。。。 我是JSON格式的新手


任何人都可以帮助我如何转换这些值并将其传递给此图表应用程序。

最后,我将需要传递给此图表应用程序的数据写入csv文件,并将其传递给highchart,如下所示:

Array Values  : 
arr[0][0] :6
arr[0][1] :0 
arr[0][2] :0 
arr[1][0] :0 
arr[1][1] :0    
arr[1][2] :0
    String CSVFileToWrite = "../../MyCSVFile.csv";//file with .csv extension
    String colkeys = "categories,jan,oct,nov";
    String rowKeys = "row1,row2";
    String[] row = rowKeys.split(",");

    String[][] array = {{"250,340,456"}, {"123,567,789"}};
    System.out.print(array[0][0]);
    System.out.println("");
    System.out.print(array[1][0]);
    try {
        File file = new File(CSVFileToWrite);
        FileWriter fw1 = new FileWriter(file);
        BufferedWriter bw = new BufferedWriter(fw1);

        int col=0;
        int row1=3;
        int i=0;
        String[][] arrayValues = new String[row1][1];
        arrayValues[0][0]=colkeys;
        for(int r=1; r < row1 ;r++) {
            arrayValues[r][col]=row[i] + "," + array[i][col];
            //System.out.println("ArrayValues["+r+"][" + col +"]" + arrayValues[r][col]);
            i++;
        }
        for(int r=0 ; r < row1 ;r++) {
            bw.write(arrayValues[r][col]);
            bw.newLine();
            bw.flush();
        }
        bw.close();
        System.out.println("File generated Successufully at location  "+ file.getAbsolutePath());
    } catch (IOException ex) {
    }
谢谢和问候


Maya

我想你指的是JavaScript而不是Java?我需要任何关于如何将Java变量值转换为json格式的示例。我现在清楚了吗?你能提供任何示例程序吗?有人能给我举个例子吗?请将你的解决方案标记为正确(接受),这样这个问题就不再标记为“未回答”。查看个人资料后:请接受所有已回答问题的答案。非常感谢。