当前位置: 首页>>代码示例>>C#>>正文


C# JArray.Add方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.Add方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.Add方法的具体用法?C# JArray.Add怎么用?C# JArray.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JArray的用法示例。


在下文中一共展示了JArray.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetColumnsFromItemsFallthroughNullTest

        public void GetColumnsFromItemsFallthroughNullTest()
        {
            JArray array = new JArray();
            array.Add(new JObject()
            {
                { "integer", 1 },
                { "value1", "string"},
                { "boolean", true },
                { "null", null }

            });
            array.Add(new JObject()
            {
                { "integer", 1 },
                { "value1", "string"},
                { "boolean", true },
                { "null", DateTime.Now }
            });

            IDictionary<string, Column> cols = storage.GetColumnsFromItems(array);

            Assert.AreEqual(4, cols.Count);

            Assert.IsTrue(cols.ContainsKey("integer"));
            // json.net makes int long
            Assert.AreEqual(typeof(long), cols["integer"].GetClrDataType());
            Assert.IsTrue(cols.ContainsKey("value1"));
            Assert.AreEqual(typeof(string), cols["value1"].GetClrDataType());
            Assert.IsTrue(cols.ContainsKey("boolean"));
            Assert.AreEqual(typeof(bool), cols["boolean"].GetClrDataType());
            Assert.IsTrue(cols.ContainsKey("null"));
            Assert.AreEqual(typeof(DateTime), cols["null"].GetClrDataType());
        }
开发者ID:jlaanstra,项目名称:azure-mobile-services,代码行数:33,代码来源:SQLiteStructuredStorageTest.cs

示例2: FormatPropertyInJson

        public void FormatPropertyInJson()
        {
            JObject query = new JObject();
            JProperty orderProp = new JProperty("order", "breadth_first");
            query.Add(orderProp);

            JObject returnFilter = new JObject();
            returnFilter.Add("body", new JValue("position.endNode().getProperty('name').toLowerCase().contains('t')"));
            returnFilter.Add("language", new JValue("javascript"));

            query.Add("return_filter", new JValue(returnFilter.ToString()));

            JObject pruneEval = new JObject();
            pruneEval.Add("body", new JValue("position.length() > 10"));
            pruneEval.Add("language", new JValue("javascript"));
            query.Add("prune_evaluator", pruneEval.ToString());

            query.Add("uniqueness", new JValue("node_global"));

            JArray relationships = new JArray();
            JObject relationShip1 = new JObject();
            relationShip1.Add("direction", new JValue("all"));
            relationShip1.Add("type", new JValue("knows"));
            relationships.Add(relationShip1);

            JObject relationShip2 = new JObject();
            relationShip2.Add("direction", new JValue("all"));
            relationShip2.Add("type", new JValue("loves"));
            relationships.Add(relationShip2);

            query.Add("relationships", relationships.ToString());
            //arr.Add(
            Console.WriteLine(query.ToString());
            //Assert.AreEqual(@"""order"" : ""breadth_first""", jobject.ToString());
        }
开发者ID:sonyarouje,项目名称:Neo4jD,代码行数:35,代码来源:DataFormatTest.cs

示例3: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            JArray array = new JArray();
            IList list = (IList)value;
            if (list.Count > 0)
            {
                JArray keys = new JArray();

                JObject first = JObject.FromObject(list[0], serializer);
                foreach (JProperty prop in first.Properties())
                {
                    keys.Add(new JValue(prop.Name));
                }
                array.Add(keys);

                foreach (object item in list)
                {
                    JObject obj = JObject.FromObject(item, serializer);
                    JArray itemValues = new JArray();
                    foreach (JProperty prop in obj.Properties())
                    {
                        itemValues.Add(prop.Value);
                    }
                    array.Add(itemValues);
                }
            }
            array.WriteTo(writer);
        }
开发者ID:Kaliido,项目名称:QuickBloxDotNetRestApi,代码行数:28,代码来源:ListCompactionConverter.cs

示例4: Run

        public async Task Run()
        {
            // Gather download count data from statistics warehouse
            IReadOnlyCollection<DownloadCountData> downloadData;
            Trace.TraceInformation("Gathering Download Counts from {0}/{1}...", StatisticsDatabase.DataSource, StatisticsDatabase.InitialCatalog);
            using (var connection = await StatisticsDatabase.ConnectTo())
            using (var transaction = connection.BeginTransaction(IsolationLevel.Snapshot))
            {
                downloadData = (await connection.QueryWithRetryAsync<DownloadCountData>(
                    _storedProcedureName, commandType: CommandType.StoredProcedure, transaction: transaction, commandTimeout: _defaultCommandTimeout)).ToList();
            }

            Trace.TraceInformation("Gathered {0} rows of data.", downloadData.Count);

            if (downloadData.Any())
            {
                SemanticVersion semanticVersion = null;

                // Group based on Package Id
                var grouped = downloadData.GroupBy(p => p.PackageId);
                var registrations = new JArray();
                foreach (var group in grouped)
                {
                    var details = new JArray();
                    details.Add(group.Key);
                    foreach (var gv in group)
                    {
                        // downloads.v1.json should only contain normalized versions - ignore others
                        if (SemanticVersion.TryParse(gv.PackageVersion, out semanticVersion)
                            && gv.PackageVersion == semanticVersion.ToNormalizedString())
                        {
                            var version = new JArray(gv.PackageVersion, gv.TotalDownloadCount);
                            details.Add(version);
                        }
                    }
                    registrations.Add(details);
                }

                var reportText = registrations.ToString(Formatting.None);

                foreach (var storageContainerTarget in Targets)
                {
                    try
                    {
                        var targetBlobContainer = await GetBlobContainer(storageContainerTarget);
                        var blob = targetBlobContainer.GetBlockBlobReference(ReportName);
                        Trace.TraceInformation("Writing report to {0}", blob.Uri.AbsoluteUri);
                        blob.Properties.ContentType = "application/json";
                        await blob.UploadTextAsync(reportText);
                        Trace.TraceInformation("Wrote report to {0}", blob.Uri.AbsoluteUri);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("Error writing report to storage account {0}, container {1}. {2} {3}",
                            storageContainerTarget.StorageAccount.Credentials.AccountName,
                            storageContainerTarget.ContainerName, ex.Message, ex.StackTrace);
                    }
                }
            }
        }
开发者ID:joyhui,项目名称:NuGet.Jobs,代码行数:60,代码来源:DownloadCountReport.cs

示例5: Get

        public IHttpActionResult Get(string name)
        {
            var json = string.Empty;
            var account = CloudStorageAccount.Parse(Config.Get("DeepStorage.OutputConnectionString"));
            var blobClient = account.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference(Config.Get("DeepStorage.HdpContainerName"));

            var prefix = string.Format("{0}.json/part-r-", name);
            var matchingBlobs = container.ListBlobs(prefix, true);
            foreach (var part in matchingBlobs.OfType<CloudBlockBlob>())
            {
                json += part.DownloadText() + Environment.NewLine;
            }

            var outputArray = new JArray();
            foreach (var line in json.Split(new[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries))
            {
                dynamic raw = JObject.Parse(line);
                var formatted = new JArray();
                formatted.Add((string)raw.eventName);
                formatted.Add((long)raw.count);
                outputArray.Add(formatted);
            }

            return Ok(outputArray);
        }
开发者ID:smartpcr,项目名称:bigdata2,代码行数:26,代码来源:QueryOutputController.cs

示例6: ToJson

 public object ToJson()
 {
     var json = new JArray();
     json.Add("face");
     json.Add(Id);
     return json;
 }
开发者ID:NitroXenon,项目名称:iQQ.Net,代码行数:7,代码来源:FaceItem.cs

示例7: UnparseEntities

            public static void UnparseEntities(JObject obj, IEnumerable<IEmbeddedLink> ELinks, IEnumerable<IEmbeddedRepresentation> EReps)
            {
                var anyLinks = ELinks != null && ELinks.Any();
                var anyReps = EReps != null && EReps.Any();

                if (anyLinks || anyReps)
                {
                    var entities = new JArray();

                    if (anyReps)
                    {
                        foreach (var rep in EReps)
                        {
                            entities.Add(UnparseEmbeddedRepresentation(rep));
                        }
                    }

                    if (anyLinks)
                    {
                        foreach (var link in ELinks)
                        {
                            entities.Add(UnparseEmbeddedLink(link));
                        }
                    }

                    obj[ENTITIES] = entities;
                }
            }
开发者ID:dariogriffo,项目名称:WebApiContrib.Formatting.JilSiren.Net,代码行数:28,代码来源:SirenJson.Unparser.cs

示例8: GetJObject

        private static JObject GetJObject(object source, Type type = null)
        {
            var dictionary = new JObject();
            var types = type ?? source.GetType();

            var attrs = GetTopAttributes(types);
            var properties = types.GetProperties();

            foreach (var property in properties)
            {
                if (attrs.ContainsKey(property.Name))
                {
                    var v = property.GetValue(source, null);

                    var attr = attrs[property.Name];
                    if (v == null)
                    {
                        dictionary.Add(attr.ItemName, null);
                        continue;
                    }

                    if (string.IsNullOrEmpty(attr.ListName))
                    {
                        var vType = v.GetType();
                        if (vType.IsPrimitive || vType.IsValueType || vType == typeof(string))
                        {
                            dictionary.Add(attr.ItemName, new JValue(property.GetValue(source, null)));
                        }
                        else
                        {
                            dictionary.Add(new JProperty(attr.ItemName, GetJObject(property.GetValue(source, null))));
                        }
                    }
                    else
                    {
                        var tempObjs = property.GetValue(source, null);
                        if (tempObjs is IList)
                        {
                            var array = new JArray();
                            foreach (var i in tempObjs as IList)
                            {
                                var iType = i.GetType();
                                if (iType.IsPrimitive || iType.IsValueType || iType == typeof(string))
                                {
                                    array.Add(new JValue(i));
                                }
                                else
                                {
                                    array.Add(GetJObject(i));
                                }
                            }

                            dictionary.Add(new JProperty(attr.ListName, new JObject(new JProperty(attr.ItemName, array))));
                        }
                    }
                }
            }

            return dictionary;
        }
开发者ID:summer-breeze,项目名称:SummerBreezeShop,代码行数:60,代码来源:JsonParser.cs

示例9: newLine

 //{{},{}}
 JArray newLine(JObject coord,JObject coord2)
 {
     JArray  line = new JArray();
     line.Add(coord);
     line.Add(coord2);
     return line;
 }
开发者ID:DrZhang,项目名称:GMS-DV,代码行数:8,代码来源:location_updata.cs

示例10: GetTestRestQuery

        private string GetTestRestQuery()
        {
            JObject query = new JObject();
            JProperty orderProp = new JProperty("order", "breadth_first");
            query.Add(orderProp);

            JObject returnFilter = new JObject();
            returnFilter.Add("body", new JValue("position.endNode().getProperty('FirstName').toLowerCase().contains('sony')"));
            returnFilter.Add("language", new JValue("javascript"));
            JProperty filter = new JProperty("return_filter", returnFilter);
            query.Add(filter);

            JArray relationships = new JArray();
            JObject relationShip1 = new JObject();
            relationShip1.Add("direction", new JValue("out"));
            relationShip1.Add("type", new JValue("wife"));
            relationships.Add(relationShip1);

            JObject relationShip2 = new JObject();
            relationShip2.Add("direction", new JValue("all"));
            relationShip2.Add("type", new JValue("loves"));
            relationships.Add(relationShip2);
            JProperty relationShipProp = new JProperty("relationships", relationships);

            query.Add(relationShipProp);

            JProperty uniqueness = new JProperty("uniqueness", "node_global");
            query.Add(uniqueness);
            JProperty maxDepth = new JProperty("max_depth", 2);
            query.Add(maxDepth);
            return query.ToString();
        }
开发者ID:sonyarouje,项目名称:Neo4jD,代码行数:32,代码来源:RESTApi_Test.cs

示例11: serializeArray

        public JArray serializeArray()
        {
            JArray verticesNode = new JArray();

            if(vertices[0] != null)
            {
                verticesNode.Add(vertices[0].serializeObject());
            }

            if(vertices[1] != null)
            {
                verticesNode.Add(vertices[1].serializeObject());
            }

            if(vertices[2] != null)
            {
                verticesNode.Add(vertices[2].serializeObject());
            }

            if(verticesNode.Count > 0)
            {
                return verticesNode;
            }

            return null;
        }
开发者ID:gbarnes12,项目名称:skyengine,代码行数:26,代码来源:Face.cs

示例12: JArray_Should_Support_Complex_Types

 public void JArray_Should_Support_Complex_Types()
 {
     var arry = new JArray();
     arry.Add(1);
     arry.Add("abc");
     var result = arry.ToString(Formatting.None);
     Assert.AreEqual("[1,\"abc\"]", result);
 }
开发者ID:kpisman,项目名称:LoveSeat,代码行数:8,代码来源:NewtonSoftTests.cs

示例13: GetExceptionResponse

 public virtual byte[] GetExceptionResponse(Exception ex)
 {
     JToken jresult = JToken.FromObject(ex.Message);
     JArray response = new JArray();
     response.Add("ERR");
     response.Add(jresult);
     return Encoding.UTF8.GetBytes(response.ToString(Formatting.None));
 }
开发者ID:scottishclaymore,项目名称:CallBox,代码行数:8,代码来源:JsonDecoder.cs

示例14: Save

        public static async Task Save(IDictionary<string, JObject> metadata, Stream packageStream, string storagePrimary, string storageContainerPackages)
        {
            string root = Guid.NewGuid().ToString();

            IList<Task<Tuple<string, Uri, Stream>>> tasks = new List<Task<Tuple<string, Uri, Stream>>>();

            using (ZipArchive archive = new ZipArchive(packageStream, ZipArchiveMode.Read, true))
            {
                foreach (ZipArchiveEntry zipEntry in archive.Entries)
                {
                    using (Stream zipEntryStream = zipEntry.Open())
                    {
                        MemoryStream memoryStream = new MemoryStream();
                        zipEntryStream.CopyTo(memoryStream);
                        memoryStream.Seek(0, SeekOrigin.Begin);
                        tasks.Add(SaveFile(memoryStream, root + "/package", zipEntry.FullName, storagePrimary, storageContainerPackages));
                    }
                }
            }

            await Task.WhenAll(tasks.ToArray());

            JArray entries = new JArray();

            foreach (Task<Tuple<string, Uri, Stream>> task in tasks)
            {
                JObject entry = new JObject();

                entry["fullName"] = task.Result.Item1;
                entry["location"] = task.Result.Item2.ToString();

                entries.Add(entry);

                task.Result.Item3.Dispose();
            }

            packageStream.Seek(0, SeekOrigin.Begin);
            Tuple<string, Uri, Stream> packageEntry = await SaveFile(packageStream, root, "package.zip", storagePrimary, storageContainerPackages);

            string packageContent = packageEntry.Item2.ToString();

            JObject packageItem = new JObject
            {
                { "@type", new JArray { MetadataHelpers.GetName(Schema.DataTypes.Package, Schema.Prefixes.NuGet), MetadataHelpers.GetName(Schema.DataTypes.ZipArchive, Schema.Prefixes.NuGet) } },
                { "location", packageContent },
                { "size", packageStream.Length },
                { "hash", Utils.GenerateHash(packageStream) }
            };

            entries.Add(packageItem);

            metadata["inventory"] = new JObject
            { 
                { "entries", entries },
                { "packageContent", packageContent }
            };
        }
开发者ID:jinujoseph,项目名称:NuGet.Services.Metadata,代码行数:57,代码来源:Artifacts.cs

示例15: CreateEventMessage

 public static byte[] CreateEventMessage(string eventType, object ev)
 {
     JToken jev = JToken.FromObject(ev);
     var message = new JArray();
     message.Add(8);
     message.Add(eventType);
     message.Add(jev);
     return Encoding.UTF8.GetBytes(message.ToString(Formatting.None));
 }
开发者ID:scottishclaymore,项目名称:CallBox,代码行数:9,代码来源:JsonWDecoder.cs


注:本文中的Newtonsoft.Json.Linq.JArray.Add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。