public void ConvertObject_ToJson_UsingParser() { _jsonParser .Parse(GivenServerSettings()) .Should() .Be(JsonContent); }
public void Should_DeserializeAJsonContent() { var validJson = GivenAValidPostStructureJsonAsString(); var obtained = _jsonParser.Parse <Post>(validJson); obtained.Should().BeOfType(typeof(Post)); }
public virtual IEnumerable <ICandidate <TEntity, TKey> > ParseMany <TEntity, TKey>(string content) where TEntity : class, IPrimaryKey <TKey> { var token = JToken.Parse(content); return(token switch { JArray array => array.Select(e => new Candidate <TEntity, TKey>(e, _jsonParser.Parse(e) as JsonObject, e.ToObject <TEntity>(_serializer))), _ => new Candidate <TEntity, TKey>(token, _jsonParser.Parse(token) as JsonObject, token.ToObject <TEntity>(_serializer)).Yield(), });
public IList <PublicContracts.HallOfFame> GetAll() { var json = _fileReader.ReadAsString(_filePath); var data = _jsonParser.Parse <IList <PublicContracts.HallOfFame> >(json); return(data); }
public void TestParseBasicJsonString() { IJsonParser jsonParser = this.GetJsonParserInstance(); IJsonNode jsonNode = jsonParser.Parse(this.basicJson); Assert.IsNull(jsonNode.Key); Assert.IsTrue(jsonNode.KeyExists("id")); Assert.IsTrue(jsonNode["id"].IsString()); Assert.AreEqual <string>("91939", (string)jsonNode["id"].InnerValue); Assert.AreEqual <Type>(typeof(string), jsonNode["id"].InnerType); Assert.IsTrue(jsonNode.KeyExists("name")); Assert.IsTrue(jsonNode["name"].IsString()); Assert.AreEqual <string>("Bruce Wayne", (string)jsonNode["name"].InnerValue); Assert.AreEqual <Type>(typeof(string), jsonNode["name"].InnerType); Assert.IsTrue(jsonNode.KeyExists("p4ssw@rd")); Assert.IsTrue(jsonNode["p4ssw@rd"].IsString()); Assert.AreEqual <string>("Th4D4rkKn!ghtR3turns", (string)jsonNode["p4ssw@rd"].InnerValue); Assert.AreEqual <Type>(typeof(string), jsonNode["p4ssw@rd"].InnerType); Assert.IsTrue(jsonNode.KeyExists("info")); Assert.IsTrue(jsonNode["info"].IsString()); Assert.AreEqual <string>("\\\"You don\'t get it son. This isn\'t a mudhole . . . it\'s an operating table . . . And I\'m the surgeon.\\\"", (string)jsonNode["info"].InnerValue); Assert.AreEqual <Type>(typeof(string), jsonNode["info"].InnerType); }
public static DataElement Parse(string json) { DataElement instace = s_parser.Parse(json); instace._json = json; instace._isSynced = true; return(instace); }
public IEnumerable <BlogFeedContent> Read(string sourceFeedUrl, IDictionary filters, Pagination pagination) { var category = ExtractCategory(filters); var feedUrl = new FeedUrl(sourceFeedUrl, category, pagination); var feedResult = _webClient.GetContent(feedUrl.Url); ValidateFeedResult(feedResult); var feedResultAsJson = _jsonParser.Parse <FeedResponseRoot>(feedResult); var blogFeedContent = _blogFeedContentParser.Parse(feedResultAsJson.posts); return(blogFeedContent); }
public IEnumerable <RailwayFare> ParseRailwayFare(string json) { // JSONを解析しやすいように調整 var adjustedJson = adjuster.Adjust(json, adjustDataBuilder.BuildRailwayFare()); // JSONを解析 var jsonObject = parser.Parse(adjustedJson); // 必要情報をオブジェクトに格納して返却 return(from dynamic o in (object[])jsonObject select new RailwayFare() { ToStation = o.toStation, FromStation = o.fromStation, IcCardFare = o.icCardFare, TicketFare = o.ticketFare, ChildIcCardFare = o.childIcCardFare, ChildTicketFare = o.childTicketFare, }); }
public async Task <IEnumerable <String> > ReceiveAsync(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { var receiveResponse = await amazonSqsClient.ReceiveMessageAsync(new ReceiveMessageRequest() { MaxNumberOfMessages = 1, QueueUrl = queueUrl, WaitTimeSeconds = 20, VisibilityTimeout = 60 }, cancellationToken); if (receiveResponse.Messages.Any()) { var deleteRequestEntries = receiveResponse .Messages .Select(message => new DeleteMessageBatchRequestEntry() { Id = message.MessageId, ReceiptHandle = message.ReceiptHandle }) .ToList(); await amazonSqsClient.DeleteMessageBatchAsync(new DeleteMessageBatchRequest() { Entries = deleteRequestEntries, QueueUrl = queueUrl }); return(receiveResponse.Messages.Select(message => { var amazonSqsMessage = jsonParser.Parse <AmazonSqsMessage>(message.Body); return amazonSqsMessage.Message; })); } } return(Enumerable.Empty <String>()); }
protected override void DeserializeSuccessFields(List <KeyValuePair <string, string> > values, IJsonParser jsonParser, XElement xml) { device_info = GetValue(values, "device_info"); openid = GetValue(values, "openid"); is_subscribe = GetValue(values, "is_subscribe") == "Y"; trade_type = (TradeType)Enum.Parse(typeof(TradeType), GetValue(values, "trade_type")); bank_type = Bank.Find(GetValue(values, "bank_type")); fee_type = Currency.Find(GetValue(values, "fee_type")); total_fee = GetIntValue(values, "total_fee") ?? 0; settlement_total_fee = GetIntValue(values, "settlement_total_fee"); coupon_fee = GetIntValue(values, "coupon_fee"); cash_fee = GetIntValue(values, "cash_fee") ?? 0; cash_fee_type = Currency.Find(GetValue(values, "cash_fee_type")); transaction_id = GetValue(values, "transaction_id"); out_trade_no = GetValue(values, "out_trade_no"); attach = GetValue(values, "attach"); time_end = DateTime.ParseExact(GetValue(values, "time_end"), "yyyMMddHHmmss", null); var d = GetValue(values, "detail"); if (d != null) { detail = jsonParser.Build <GoodDetails>(jsonParser.Parse(d)); } }
public async Task <IEnumerable <News> > GetNews( IEnumerable <string> sources, IEnumerable <string> symbols = null, Category category = Category.None, string keyword = "", int maxRecords = 30, DateTime?startDate = null, DisplayType displayType = DisplayType.full, bool images = true, int?storyID = null, bool rss = false, string rssTitle = "", IEnumerable <string> fields = null) { var url = BaseUrl + $"getNews.json?apikey={ApiKey}" + $"&sources={string.Join(",", sources)}" + $"{(symbols != null ? $"&symbols={string.Join(",", symbols)}" : "")}" + $"{(category != Category.None ? $"category={category}" : "")}" + $"{(!string.IsNullOrWhiteSpace(keyword) ? $"&keyword={keyword}" : "")}" + $"&maxRecords={maxRecords}" + $"{(startDate.HasValue ? $"&startDate={startDate.Value}" : "")}" + $"&displayType={displayType}" + $"&images={images}" + $"{(storyID.HasValue ? $"&storyId={storyID.Value}" : "")}" + $"&rss={rss}" + $"{(!string.IsNullOrWhiteSpace(rssTitle) ? $"&rssTitle={rssTitle}" : "")}" + $"{(fields != null ? $"&fields={string.Join(",", fields)}" : "")}"; var json = await _httpClient.GetStringAsync(url); return(_jsonParser.Parse <News>(json)); }
public async Task <IEnumerable <Employee> > GetData(string url) { string employeesJson = await httpClient.GetContentAsync(url); return(jsonParser.Parse(employeesJson)); }