/// <summary> /// Returns a List of EliteListing objects from a EDDB Json Array. /// JsonReader MUST currently point to the StartArray token for the Listing Array. /// </summary> /// <param name="jsonReader">JsonReader populated with the Listing Array</param> /// <returns>List of populated EliteListing Data</returns> private List<EliteListing> _ParseJsonListing(JsonTextReader jsonReader) { List<EliteListing> listings = new List<EliteListing>(); if (jsonReader.TokenType != JsonToken.StartArray) { AerDebug.LogError("_ParseJsonListing must be called at the start of an Array"); return null; } EliteListing currentListing = null; while (jsonReader.TokenType != JsonToken.EndArray) { jsonReader.Read(); switch (jsonReader.TokenType) { case JsonToken.StartObject: currentListing = new EliteListing(); break; case JsonToken.EndObject: listings.Add(currentListing); break; case JsonToken.PropertyName: switch (jsonReader.Value.ToString()) { case "id": currentListing.id = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "station_id": currentListing.StationId = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "commodity_id": currentListing.Commodity = GetCommodity(jsonReader.ReadAsInt32().GetValueOrDefault()); break; case "supply": currentListing.Supply = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "buy_price": currentListing.BuyPrice = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "sell_price": currentListing.SellPrice = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "demand": currentListing.Demand = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "collected_at": currentListing.UpdatedAt = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "update_count": currentListing.UpdateCount = jsonReader.ReadAsInt32().GetValueOrDefault(); break; default: AerDebug.LogError("Unknown JSON property name: " + jsonReader.Value.ToString()); break; } break; case JsonToken.EndArray: break; default: AerDebug.LogError("Unknown token type in listing list, " + jsonReader.TokenType); break; } } return listings; }
/// <summary> /// Returns a List of EliteListing objects from a EDDB Json Array. /// JsonReader MUST currently point to the StartArray token for the Listing Array. /// </summary> /// <param name="jsonReader">JsonReader populated with the Listing Array</param> /// <returns>List of populated EliteListing Data</returns> private List <EliteListing> _ParseJsonListing(JsonTextReader jsonReader) { List <EliteListing> listings = new List <EliteListing>(); if (jsonReader.TokenType != JsonToken.StartArray) { AerDebug.LogError("_ParseJsonListing must be called at the start of an Array"); return(null); } EliteListing currentListing = null; while (jsonReader.TokenType != JsonToken.EndArray) { jsonReader.Read(); switch (jsonReader.TokenType) { case JsonToken.StartObject: currentListing = new EliteListing(); break; case JsonToken.EndObject: listings.Add(currentListing); break; case JsonToken.PropertyName: switch (jsonReader.Value.ToString()) { case "id": currentListing.id = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "station_id": currentListing.StationId = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "commodity_id": currentListing.Commodity = GetCommodity(jsonReader.ReadAsInt32().GetValueOrDefault()); break; case "supply": currentListing.Supply = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "buy_price": currentListing.BuyPrice = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "sell_price": currentListing.SellPrice = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "demand": currentListing.Demand = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "collected_at": currentListing.UpdatedAt = jsonReader.ReadAsInt32().GetValueOrDefault(); break; case "update_count": currentListing.UpdateCount = jsonReader.ReadAsInt32().GetValueOrDefault(); break; default: AerDebug.LogError("Unknown JSON property name: " + jsonReader.Value.ToString()); break; } break; case JsonToken.EndArray: break; default: AerDebug.LogError("Unknown token type in listing list, " + jsonReader.TokenType); break; } } return(listings); }