package json;
import java.io.*;
import tool.readfile;
import tool.catchword;
public class pro {
String[] name=new String[101];
int[] age=new int[101];
int s,sx;
String[] credit=new String[11];
String[] var=new String[11];
int creditnumber,datanumber;
String[][] data=new String[501][10];
String[] subdata=new String[501];
int subnumber;
public static void main(String[] args) {
pro test=new pro();
}
pro(){
readfile sub4=new readfile();
sub4.makedata("member.txt","UTF-8");
subdata=sub4.data;
datanumber=sub4.datanumber;
for(s=1;s<datanumber+1;s++){
System.out.println(subdata[s]);
catchword sub2=new catchword();
data[s][1]=sub2.makedata(subdata[s],"ARTIST");
data[s][2]=sub2.makedata(subdata[s],"WYEAR");
}
credit[1]="artist";
credit[2]="year";
var[1]="string";
var[2]="num";
creditnumber=2;
json sub=new json();
sub.data=data;
sub.datanumber=datanumber;
sub.creditnumber=creditnumber;
sub.credit=credit;
sub.var=var;
sub.makedata("member.json");
}
}
package json;
import java.io.*;
public class json{
String[] name=new String[101];
String str;
int[] age=new int[101];
int s,sx;
String[] credit=new String[11];
String[] var=new String[11];
int creditnumber,datanumber;
String[][] data=new String[5001][10];
String[] jdata=new String[5000];
void makedata(String file){
for(s=1;s<datanumber+1 ;s++){
jdata[s]=subdata(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(jdata[s]);
pw.println(",");
}
pw.println(jdata[datanumber]);
pw.println("]");
System.out.println("ファイルに書きこみました。");
pw.close();
} catch(IOException ep){ System.out.println("入出力エラーです。"); }
}
String subdata(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年09月29日 06:15