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 ItemConstructor extends ElementConstructor{ public ItemConstructor(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 goods = jsonObject.getJSONArray("goods"); Map attribute = null; Iterator attrIter = null; for(JSONObject good:goods.toJavaList(JSONObject.class)) { category = (String) good.get("category"); JSONArray items = good.getJSONArray("items"); for (JSONObject item : items.toJavaList(JSONObject.class)) { name = (String) item.get("name"); description = (String) item.get("intro"); attribute = JSONObject.toJavaObject(item.getJSONObject("attr"), Map.class); attrIter = attribute.keySet().iterator(); while (attrIter.hasNext()) { attrName = attrIter.next(); attrValue = attribute.get(attrName); configText.append("-varInitial-|" + category + "_" + name + "_" + attrName + "|" + attrValue + "\n"); } } } } }