public static void AddElement(RjElement parent, ExcelWorksheet sheet, ExcelRow row, int index, string key) { string typeString = GetSheetCell(sheet, KEY_TYPE_ROW_INDEX, index).ToString(); RjValueType type = RjValueType.INT; if (typeString == "int") { type = RjValueType.INT; } else if (typeString == "float") { type = RjValueType.FLOAT; } else if (typeString == "bool") { type = RjValueType.BOOL; } else { type = RjValueType.STRING; } // parent.AddElement(new RjValue(key, row[index] ,_value_type, GetSheetCell(sheet, DES_TYPE_ROW_INDEX, index).ToString())); var valueString = GetSheetCell(sheet, row.Row, index).ToString(); var rjValue = new RjValue(key, valueString, type, GetSheetCell(sheet, DES_TYPE_ROW_INDEX, index).ToString()); parent.AddElement(rjValue); }
public static void Parse(RjElement parent, ExcelWorksheet sheet, ExcelRow row, int index, string key, int maxNum, bool needTakeValue = true) { if (string.IsNullOrEmpty(key) && (parent.GetClassType() != RjClassType.COLL)) { if (index < maxNum - 1) { Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum); } return; } // filter " and : key = key.Replace("\"", ""); key = key.Replace(":", ""); for (int i = 0; i < key.Length; ++i) { if (key[i] == '[') { //before string _key_before = key.Substring(0, i); //after string _key_after = key.Substring(i + 1, key.Length - i - 1); RjColl _coll = new RjColl(_key_before); _coll.SetParent(parent); parent.AddElement(_coll); if (string.IsNullOrEmpty(_key_after)) { //must add the value AddElement(_coll, sheet, row, index, null); Parse(_coll, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum); } else { Parse(_coll, sheet, row, index, _key_after, maxNum); } return; } else if (key[i] == '{') { string[] _kks = key.Split('{'); RjData _coll = new RjData(_kks[0]); _coll.SetParent(parent); parent.AddElement(_coll); Parse(_coll, sheet, row, index, _kks[1], maxNum); return; } else if (key[i] == ']') { //string _raw_key=_sheet.Rows[mc_key_row][_index]; if (needTakeValue) { AddElement(parent, sheet, row, index, null); } parent = parent.GetPerent(); if (key.Length == 1) { if (index < maxNum - 1) { Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum); } } else { string _key_after = key.Substring(i + 1, key.Length - i - 1); Parse(parent, sheet, row, index, _key_after, maxNum); } return; } else if (key[i] == '}') { string _key_before = key.Substring(0, i); string _key_after = key.Substring(i + 1, key.Length - i - 1); // Debug.Log("before:"+_key_before+" after:"+_key_after); bool _need_take = true; if (!string.IsNullOrEmpty(_key_before)) { AddElement(parent, sheet, row, index, _key_before); _need_take = false; } parent = parent.GetPerent(); if (string.IsNullOrEmpty(_key_after)) { if (index < maxNum - 1) { Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum); } } else { Parse(parent, sheet, row, index, _key_after, maxNum, _need_take); } return; } } AddElement(parent, sheet, row, index, key); if (index < maxNum - 1) { Parse(parent, sheet, row, index + 1, GetSheetCell(sheet, KEY_ROW_INDEX, index + 1).ToString(), maxNum); } }