package makejson;
import java.io.*;
import tool.readfile;
import tool.catchword;
public class pro {
int s,sx;
String[] credit=new String[25];
String[] var=new String[25];
int creditnumber,datanumber;
String[][] data=new String[50001][25];
String[] subdata=new String[50001];
int subnumber;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
readfile sub4=new readfile();
sub4.makedata("wiki.txt","UTF-8");
subdata=sub4.data;
datanumber=sub4.datanumber;
for(s=1;s<datanumber+1;s++){
catchword sub2=new catchword();
data[s][1]=sub2.makedata(subdata[s],"ARTIST");;
data[s][2]=sub2.makedata(subdata[s],"WYEAR");;
data[s][3]=sub2.makedata(subdata[s],"WMONTH");
data[s][4]=sub2.makedata(subdata[s],"POINT");
}
credit[2]="year";
credit[3]="month";
credit[1]="artist";
credit[4]="point";
var[2]="num";
var[1]="string";
var[3]="num";
var[4]="num";
creditnumber=4;
json sub=new json();
sub.data=data;
sub.datanumber=datanumber;
sub.creditnumber=creditnumber;
sub.credit=credit;
sub.var=var;
sub.makedata("wiki.json");
}
}
package makejson;
import java.io.*;
public class json{
String[] name=new String[25];
String str;
int s,sx;
String[] credit=new String[25];
String[] var=new String[25];
int creditnumber,datanumber;
String[][] data=new String[50001][25];
String[] json=new String[50000];
void makedata(String file){
for(s=1;s<datanumber+1 ;s++){
json[s]=jsondata(s);
}
writefile(file);
}
void writefile(String file){
int z1;
try{
PrintWriter pw = new PrintWriter (new BufferedWriter(new FileWriter(file)));
pw.println("[");
for(s=1;s<datanumber;s++){
pw.print(json[s]);
pw.println(",");
}
pw.println(json[datanumber]);
pw.println("]");
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String jsondata(int s){
String strx;
int sx;
strx="{";
for(sx=1;sx<creditnumber;sx++){
strx=strx+credit(credit[sx]);
if(var[sx].indexOf("string")>-1 )strx=strx+change(data[s][sx]);
if(var[sx].indexOf("num")>-1 )strx=strx+data[s][sx];
strx=strx+",";
}
sx=creditnumber;
strx=strx+credit(credit[sx]);
if(var[sx].indexOf("string")>-1 )strx=strx+change(data[s][sx]);
if(var[sx].indexOf("num")>-1 )strx=strx+data[s][sx];
strx=strx+"}";
return strx;
}
String credit(String str){
String strx;
strx=change(str)+":";
return strx;
}
String change(String str){
String strx;
strx="\""+str+"\"";
return strx;
}
}
最終更新:2013年10月01日 12:45