Skip to content

Instantly share code, notes, and snippets.

@adison
Created August 9, 2013 00:43
Show Gist options
  • Save adison/6190247 to your computer and use it in GitHub Desktop.
Save adison/6190247 to your computer and use it in GitHub Desktop.
generate json, json like data by Java
/*
this code tis purposed to make data for AngularJS from data kind of
province district
data-A1 data-B1
data-A1 data-B2
data-A1 data-B3
to
[province: "data-A1", districts: [
{distict: "data-B1"},
{distict: "data-B2"},
{distict: "data-B3"}
]]
*/
while(vRs.next()){
// 是否同一組
if(!vCurrectCountyID.equals(vRs.getString("province"))
|| vCurrectCountyID.equals("")){
vCurrectCountyID = vRs.getString("province");
vCurrentCountyName = vRs.getString("city_name");
if(countyCounter !=0)
vRegionModel += "]},";
countyCounter ++;
vRegionModel += "{cName: '" + vCurrentCountyName + "', cID: '" + vCurrectCountyID + "',diss: [{dID:'0', dName:'全區'},";
} else
vRegionModel += ",";
vRegionModel += "{dID: '" + vRs.getString("areacode").trim() + "', dName:'" + vRs.getString("area_name").trim() +"'}";
}
vRegionModel.substring(0, vRegionModel.length()-2);
vRegionModel += "]}];";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment