public static Person Create(JsonValue personValue) { Person person = new Person(); JsonObject jsonData = personValue.GetObject(); int id; IJsonValue idValue; if (jsonData.TryGetValue("id", out idValue)) { if (idValue.ValueType == JsonValueType.String) { if (int.TryParse(jsonData.GetNamedString("id"), out id)) { person.Id = id; } } else if (idValue.ValueType == JsonValueType.Number) { if (int.TryParse(jsonData.GetNamedNumber("id").ToString(), out id)) { person.Id = id; } } } person.FirstName = jsonData.GetNamedString("firstName"); person.LastName = jsonData.GetNamedString("lastName"); return person; }
private static OrderItem Create(JsonValue value) { OrderItem item = new OrderItem(); JsonObject data = value.GetObject(); int id; double price, quantity; item.Name = data.GetNamedString("name"); item.Description = data.GetNamedString("description"); if (int.TryParse(data.GetNamedNumber("id").ToString(), out id)) { item.Id = id; } if (double.TryParse(data.GetNamedNumber("price").ToString(), out price)) { item.Price = price; } if (double.TryParse(data.GetNamedNumber("quantity").ToString(), out quantity)) { item.Quantity = quantity; } return item; }
public static IList<OrderItem> CreateList(JsonValue jsonValue) { IList<OrderItem> items = new List<OrderItem>(); JsonArray array = jsonValue.GetArray(); foreach (JsonValue value in array) { items.Add(OrderItemFactory.Create(value)); } return items; }
public static Order Create(JsonValue orderJson) { Order order = new Order(); JsonObject data = orderJson.GetObject(); int id; if (int.TryParse(data.GetNamedNumber("id").ToString(), out id)) { order.Id = id; } order.Items = OrderItemFactory.CreateList(data.GetNamedValue("items")); order.Customer = PersonFactory.Create(data.GetNamedValue("customer")); return order; }
public static Person Create(JsonValue personValue) { Person person = new Person(); JsonObject jsonObject = personValue.GetObject(); int? id = jsonObject.GetIntegerValue("id"); if (id.HasValue) { person.Id = id.Value; } person.FirstName = jsonObject.GetStringValue("firstName"); person.LastName = jsonObject.GetStringValue("lastName"); bool? isOnWestCoast = jsonObject.GetBooleanValue("isOnWestCoast"); if (isOnWestCoast.HasValue) { person.IsOnWestCoast = isOnWestCoast.Value; } return person; }
public static extern bool TryParse([In] string input, out JsonValue result);
internal static ThemeUniqueItem FromJson(JsonValue jsonValue) { if (jsonValue == null) { return null; }; ThemeUniqueItem item = new ThemeUniqueItem(); item.Caption = jsonValue.GetObject()["caption"].GetStringEx(); item.Style = ServerStyle.FromJson(jsonValue.GetObject()["style"].GetObjectEx()); item.Unique = jsonValue.GetObject()["unique"].GetStringEx(); item.Visible = jsonValue.GetObject()["visible"].GetBooleanEx(); return item; }
public async Task <string> CreateTokenAsync(Card card, bool test) { if (card == null) { throw new ArgumentNullException(nameof(card)); } if (_client != null) { try { var parameters = new JsonObject { { "card", new JsonObject { { "number", JsonValue.CreateStringValue(card.Number) }, { "expiration_month", JsonValue.CreateStringValue(card.ExpiryMonth.ToString("D2")) }, { "expiration_year", JsonValue.CreateStringValue(card.ExpiryYear.ToString("D2")) }, { "security_code", JsonValue.CreateStringValue(card.CVC) } } } }; var body = parameters.ToString(); var url = test ? "https://tgb-playground.smart-glocal.com/cds/v1/tokenize/card" : "https://tgb.smart-glocal.com/cds/v1/tokenize/card"; var request = new HttpRequestMessage(HttpMethod.Post, url); var requestContent = new StringContent(body, Encoding.UTF8, "application/json"); request.Headers.TryAddWithoutValidation("X-PUBLIC-TOKEN", _publicToken); request.Content = requestContent; var response = await _client.SendAsync(request); var content = await response.Content.ReadAsStringAsync(); var json = JsonObject.Parse(content); var resultData = json.GetNamedObject("data", null); if (resultData == null) { Client.Execute(new AddLogMessage(5, $"Failed to process payment using Smart Glocal: {content}")); return(null); } var token = resultData.GetNamedString("token", string.Empty); if (token == null) { Client.Execute(new AddLogMessage(5, $"Failed to process payment using Smart Glocal: {content}")); return(null); } return(token); } catch (Exception ex) { Client.Execute(new AddLogMessage(5, $"Failed to process payment using Smart Glocal: {ex}")); return(null); } } return(null); }
private static GradeInfo GetGradeInfo(JsonValue gradeValue) { JsonObject gradeObject = gradeValue.GetObject(); GradeInfo info = new GradeInfo(); info.CourseCode = gradeObject.GetNamedString("course_code"); info.CourseTitle = gradeObject.GetNamedString("course_title"); info.CourseType = gradeObject.GetNamedString("course_type"); info.CourseOption = gradeObject.GetNamedString("option").ToUpper(); info.Credits = (ushort)gradeObject.GetNamedNumber("credits"); info.Grade = gradeObject.GetNamedString("grade")[0]; info.AssignExamDate(gradeObject.GetNamedString("exam_held")); if (info.CourseOption == "NIL") info.CourseOption = ""; return info; }