當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。