コード例 #1
0
        private void ExtractJson(string json, IUpdatableRow output)
        {
            //var jsonReader = new JsonTextReader(new StringReader(tokens[0]));
            var jsonReader = new JsonTextReader(new StringReader(json));

            while (jsonReader.Read())
            {
                if (jsonReader.TokenType == JsonToken.StartObject)
                {
                    var token = JToken.Load(jsonReader);
                    // Rows
                    //  All objects are represented as rows
                    foreach (JObject o in token.SelectTokens("data[*]"))
                    {
                        //Console.WriteLine($"JObject: {o}");
                        // All fields are represented as columns
                        //this.JObjectToRow(o, output);
                        //mapToColumns(o, output);
                        //yield return output.AsReadOnly();
                        //var tokens = o.SelectTokens("$.data.author");
                        var sqlMap = SqlMap.Create(MapHelper <string>(o, "$.data.author"));
                        if (sqlMap != null && sqlMap.Count > 0)
                        {
                            Console.WriteLine("SqlMap exists");
                            var tempMap = output.Get <SqlMap <string, string> >("contexts.data.author");

                            if (tempMap != null && tempMap.Count > 0)
                            {
                                Console.WriteLine("tempMAp exists");

                                var combinedDict = new Dictionary <string, string>();
                                tempMap.Keys.ToList().ForEach(key => combinedDict.Add(key, tempMap[key]));
                                sqlMap.Keys.ToList().ForEach(key => combinedDict.Add(key, sqlMap[key]));

                                output.Set("contexts.data.author", new SqlMap <string, string>(combinedDict));
                            }
                            else
                            {
                                output.Set("contexts.data.author", sqlMap);
                            }
                        }
                    }
                }
            }
        }