private void LoadFromJSON(JsonObject obj) { foreach (string key in obj.Keys) { string theKey = key; if (key.Contains("_")) theKey = key.Replace("_", "-"); // Chargify seems to return different keys based on xml or json return type switch (theKey) { case TotalCountKey: _totalCount = obj.GetJSONContentAsInt(key); break; case CurrentPageKey: _currentPage = obj.GetJSONContentAsInt(key); break; case TotalPagesKey: _totalPages = obj.GetJSONContentAsInt(key); break; case PerPageKey: _perPage = obj.GetJSONContentAsInt(key); break; case MetadataKey: _metadata = new List<IMetadata>(); JsonArray viewObj = obj[key] as JsonArray; if (viewObj != null && viewObj.Items != null && viewObj.Length > 0) { foreach (JsonValue item in viewObj.Items) { var newObj = new Metadata(); var hasData = false; var itemObj = (JsonObject)item; foreach (string subItemKey in itemObj.Keys) { switch (subItemKey) { case "resource_id": hasData = true; newObj.ResourceID = obj.GetJSONContentAsInt(subItemKey); break; case "name": hasData = true; newObj.Name = obj.GetJSONContentAsString(subItemKey); break; case "value": hasData = true; newObj.Value = obj.GetJSONContentAsString(subItemKey); break; default: break; } } if (hasData) { _metadata.Add(newObj); } } } break; default: break; } } }
private void LoadFromJSON(JsonObject obj) { // loop through the keys of this JsonObject to get stats info, and parse it out foreach (string key in obj.Keys) { switch (key) { case SellerNameKey: _sellerName = obj.GetJSONContentAsString(key); break; case SiteNameKey: _siteName = obj.GetJSONContentAsString(key); break; case StatsKey: JsonObject statsObj = obj[key] as JsonObject; foreach (string innerKey in statsObj.Keys) { switch (innerKey) { case TotalSubscriptionsKey: _totalSubscriptions = statsObj.GetJSONContentAsInt(innerKey); break; case SubscriptionsTodayKey: _subscriptionsToday = statsObj.GetJSONContentAsInt(innerKey); break; case TotalRevenueKey: _totalRevenue = statsObj.GetJSONContentAsString(innerKey); break; case RevenueTodayKey: _revenueToday = statsObj.GetJSONContentAsString(innerKey); break; case RevenueThisMonthKey: _revenueThisMonth = statsObj.GetJSONContentAsString(innerKey); break; case RevenueThisYearKey: _revenueThisYear = statsObj.GetJSONContentAsString(innerKey); break; default: break; } } break; default: break; } } }
private void LoadFromJSON(JsonObject obj) { // loop through the keys of this JsonObject to get invoice info, and parse it out foreach (string key in obj.Keys) { switch (key) { case IDKey: m_id = obj.GetJSONContentAsInt(key); break; case SubscriptionIDKey: _subscriptionID = obj.GetJSONContentAsInt(key); break; case StatementIDKey: _statementID = obj.GetJSONContentAsInt(key); break; case SiteIDKey: _siteID = obj.GetJSONContentAsInt(key); break; case StateKey: _state = obj.GetJSONContentAsSubscriptionState(key); break; case TotalAmountInCentsKey: _totalAmountInCents = obj.GetJSONContentAsInt(key); break; case PaidAtKey: _paidAt = obj.GetJSONContentAsDateTime(key); break; case CreatedAtKey: _createdAt = obj.GetJSONContentAsDateTime(key); break; case UpdatedAtKey: _updatedAt = obj.GetJSONContentAsDateTime(key); break; case AmountDueInCentsKey: _amountDueInCents = obj.GetJSONContentAsInt(key); break; case NumberKey: _number = obj.GetJSONContentAsString(key); break; case ChargesKey: _charges = new List<ICharge>(); JsonArray chargesArray = obj[key] as JsonArray; if (chargesArray != null) { foreach (JsonObject charge in chargesArray.Items) { _charges.Add(charge.GetJSONContentAsCharge("charge")); } } // Sanity check, should be equal. if (chargesArray.Length != _charges.Count) { throw new JsonParseException(string.Format("Unable to parse charges ({0} != {1})", chargesArray.Length, _charges.Count)); } break; case PaymentsAndCreditsKey: break; default: break; } } }