public void ReadElement(SimpleElementAttribute attribute, object reader, object receiver, ReadSettings settings, ObjectPropertyInfo info, object serializerData) { if (attribute.IsMultiple) { JsonTextReader jsonReader = reader.Convert <JsonTextReader>(); IList list = attribute.GetList(receiver, info); // 考虑支持多层次Array读取,外层Object可能读取过,所以这里做判断对此进行屏蔽 2019.6.24 if (jsonReader.TokenType != JsonToken.StartArray) { AssertRead(jsonReader); } AssertReadState(jsonReader, JsonToken.StartArray, info.PropertyName); while (jsonReader.Read()) { if (jsonReader.TokenType == JsonToken.EndArray) { break; } object value = GetSimpleValue(jsonReader, receiver, settings, info, attribute.AutoTrim); list.Add(value); } } else { ReadSimpleValue(reader, receiver, settings, info, attribute.AutoTrim); } }
public static void AddElementValue(SimpleElementAttribute attribute, object receiver, ObjectPropertyInfo info, object objValue) { if (attribute.IsMultiple) { IList list = attribute.GetList(receiver, info); list.Add(objValue); } else { info.SetValue(receiver, objValue); } }