package gameDesign; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import db.SqlHelper; import entity.UserInfo; import java.util.Iterator; import java.util.Map; public class CharacterConstructor extends ElementConstructor { public CharacterConstructor(SqlHelper helper, int botId) { super(); this.helper = helper; this.botId = botId; } public void construct(JSONObject jsonObject, UserInfo userinfo) { String category, name, description, attrName, attrValue; JSONArray allNPC = jsonObject.getJSONArray("npc"); Map attribute = null; Iterator attrIter = null; for (JSONObject npc : allNPC.toJavaList(JSONObject.class)) { category = (String) npc.get("category"); JSONArray characters = npc.getJSONArray("characters"); for (JSONObject character : characters.toJavaList(JSONObject.class)) { name = (String) character.get("name"); description = (String) character.get("intro"); attribute = JSONObject.toJavaObject(character.getJSONObject("attr"), Map.class); attrIter = attribute.keySet().iterator(); while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); varInitialMap.put(category + "_" + name + "_" + attrName, attrValue); } } } } }