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


C# JObject.AddFirst方法代码示例

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


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

示例1: Page_Load

 protected void Page_Load(object sender, EventArgs e)
 {
     Response.Clear();
     string body = string.Empty;
     using (StreamReader streamReader = new StreamReader(Request.InputStream))
     {
         body = streamReader.ReadToEnd();
     }
     JObject jObject = null;
     switch(Request.ContentType)
     {
         case "application/json":
             jObject = JsonConvert.DeserializeObject<JObject>(body);
             break;
         case "application/x-www-form-urlencoded":
             jObject = new JObject();
             foreach (string postField in Request.Form.AllKeys)
             {
                 jObject.AddFirst(new JProperty(postField, Request.Form[postField]));
             }
             break;
     }
     Response.Write(JsonConvert.SerializeObject(jObject));
     Response.ContentType = "application/json";
 }
开发者ID:rajeshwarn,项目名称:PortableRest,代码行数:25,代码来源:test.aspx.cs

示例2: WriteJson

        /// <summary>Writes the JSON representation of the object.</summary>
        /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter" /> to write to.</param>
        /// <param name="value">The value.</param>
        /// <param name="serializer">The calling serializer.</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var exception = value as Exception;
            if (exception != null)
            {
                var resolver = serializer.ContractResolver as DefaultContractResolver ?? _defaultContractResolver;

                var jObject = new JObject();
                jObject.Add(resolver.GetResolvedPropertyName("discriminator"), exception.GetType().Name);
                jObject.Add(resolver.GetResolvedPropertyName("Message"), exception.Message);
                jObject.Add(resolver.GetResolvedPropertyName("StackTrace"), _hideStackTrace ? "HIDDEN" : exception.StackTrace);
                jObject.Add(resolver.GetResolvedPropertyName("Source"), exception.Source);
                jObject.Add(resolver.GetResolvedPropertyName("InnerException"),
                    exception.InnerException != null ? JToken.FromObject(exception.InnerException, serializer) : null);

                foreach (var property in GetExceptionProperties(value.GetType()))
                {
                    var propertyValue = property.Key.GetValue(exception);
                    if (propertyValue != null)
                    {
                        jObject.AddFirst(new JProperty(resolver.GetResolvedPropertyName(property.Value),
                            JToken.FromObject(propertyValue, serializer)));
                    }
                }

                value = jObject;
            }

            serializer.Serialize(writer, value);
        }
开发者ID:NSwag,项目名称:NSwag,代码行数:34,代码来源:JsonExceptionConverter.cs

示例3: WriteJson

 public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
 {
     var converters = serializer.Converters.Where(x => !(x is TypeInfoConverter)).ToArray();
     var jObject = new JObject();
     jObject.AddFirst(new JProperty("Type", value.GetType().FullName));
     jObject.Add(new JProperty("Data", JToken.FromObject(value)));
     jObject.WriteTo(writer, converters);
 }
开发者ID:SpagAachen,项目名称:Ballz,代码行数:8,代码来源:TypeInfoConverter.cs

示例4: Delete

        // DELETE: api/DataTablesPatient/5
        public void Delete(int id)
        {
            JObject reply = new JObject();
            try
            {

            }
            catch (Exception ex)
            {
                reply.AddFirst("DELETE Patients Error");
                reply.Add("Error", JToken.Parse(ex.Message.ToString()));
                reply.Add("Detailed error:", JToken.Parse(ex.InnerException.ToString()));
            }
            //return reply;
        }
开发者ID:martynlesbirel,项目名称:Facility,代码行数:16,代码来源:DataTablesPatientController.cs

示例5: WithODataEntityResponseBody

        public static IOwinResponse WithODataEntityResponseBody(this IOwinResponse owinResponse, string baseAddress, 
            string entitySetName, JObject response, params JProperty[] additionalProperties)
        {
            if (response == null)
                return owinResponse;

            foreach (var additionalProperty in additionalProperties.Reverse())
            {
                response.AddFirst(additionalProperty);
            }

            response.AddOdataContext(baseAddress, entitySetName);

            owinResponse.Write(response.ToString());

            return owinResponse;
        }
开发者ID:iambmelt,项目名称:Vipr,代码行数:17,代码来源:OwinResponseExtensions.cs

示例6: WriteJson

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            JToken t = JToken.FromObject(value);

            //			if (t.Type != JTokenType.Object)
            //			{
            //				t.WriteTo(writer);
            //			}
            //			else
            //			{
            JObject o = (JObject)t;

            var comp = new JObject();

            comp.AddFirst(new JProperty(value.GetType().Name, o));

            comp.WriteTo(writer);
            //			}
        }
开发者ID:ZloyZlobin,项目名称:JoustCommon,代码行数:19,代码来源:ComponentJsonConverter.cs

示例7: GetDrugPerscription

        // GET: api/DataTableDrugs/5
        //[ResponseType(typeof(Drug))]
        public HttpResponseMessage GetDrugPerscription(string summary, char id, [FromUri] dataTableRequest thisRequest)
        {
            HttpResponseMessage reply = new HttpResponseMessage();

            try
            {

                reply.StatusCode = HttpStatusCode.OK;
            }
            catch (Exception ex)
            {
                string message = ex.Message.ToString();
                JObject errorJSON = new JObject();
                errorJSON.AddFirst("GET Drugs Error");
                errorJSON.Add("Error", JToken.Parse(ex.Message.ToString()));
                errorJSON.Add("Detailed error:", JToken.Parse(ex.InnerException.ToString()));

                reply.Content = new StringContent(errorJSON.ToString(), Encoding.Unicode);
                reply.StatusCode = HttpStatusCode.InternalServerError;
            }

            return reply;
        }
开发者ID:martynlesbirel,项目名称:Facility,代码行数:25,代码来源:DrugPerscriptionsController.cs

示例8: Put

        // PUT: api/DataTablesPatient/5
        public void Put(int id, [FromBody]string value)
        {
            JObject reply = new JObject();
            try
            {

            }
            catch (Exception ex)
            {
                reply.AddFirst("PUT Patients Error");
                reply.Add("Error", JToken.Parse(ex.Message.ToString()));
                reply.Add("Detailed error:", JToken.Parse(ex.InnerException.ToString()));
            }
            //return reply;
        }
开发者ID:martynlesbirel,项目名称:Facility,代码行数:16,代码来源:DataTablesPatientController.cs

示例9: SerializeEntity

        private JObject SerializeEntity(Node subject, IEnumerable<EntityQuad> quads, Node graphName, bool nativeTypes, bool useRdfType, JObject listsInGraph)
        {
            var groups = from quad in quads
                         where quad.Subject == subject && quad.Graph == graphName
                         group quad.Object by quad.Predicate into g
                         select new { Predicate = (g.Key == RdfType ? useRdfType ? RdfType : Node.ForLiteral(Type) : g.Key), Objects = g }
                             into selection
                             orderby selection.Predicate
                             select selection;

            var result = new JObject();
            int i = 0;

            foreach (var objectGroup in groups)
            {
                JProperty res;
                if (objectGroup.Predicate == RdfType || objectGroup.Predicate == Node.ForLiteral(Type))
                {
                    if (useRdfType)
                    {
                        res = new JProperty(new JProperty(RdfType.ToString(), new JArray(from o in objectGroup.Objects select GetPropertyValue(o, nativeTypes, listsInGraph))));
                    }
                    else
                    {
                        res = new JProperty(new JProperty(Type, new JArray(from o in objectGroup.Objects select o.ToString())));
                    }
                }
                else
                {
                    res = new JProperty(new JProperty(objectGroup.Predicate.Uri.ToString(), new JArray(from o in objectGroup.Objects select GetPropertyValue(o, nativeTypes, listsInGraph))));
                }

                if (i == 0)
                {
                    result.AddFirst(new JProperty(Id, subject.IsBlank ? "_:" + subject.BlankNode : subject.ToString()));
                    i++;
                }

                result.Add(res);
            }

            return result;
        }
开发者ID:rafalrosochacki,项目名称:RomanticWeb,代码行数:43,代码来源:JsonLdProcessor.cs

示例10: UpdateExistingResource

        /// <summary>
        /// Updates an existing resource.
        /// </summary>
        /// <param name="existingId">The existing resource identifier.</param>
        /// <param name="resourceDefinition">The resource definition.</param>
        /// <returns>The async <see cref="Task"/>.</returns>
        private async Task UpdateExistingResource(string existingId, JObject resourceDefinition)
        {
            _logProvider.LogMessage($"Updating existing {_resourceType}: '{_resourceId}' ");

            using (var client = HttpClientFactory.GetClient(_accountDetails, "application/json"))
            {
                resourceDefinition.AddFirst(new JProperty("id", existingId));
                RemovePropertiesUnsupportedForEdit(resourceDefinition);
                var url = GetApiUrl(_resourceApi.EditUrl);
                var content = new StringContent(resourceDefinition.ToString(), Encoding.UTF8, "application/json");
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); // CaaS bug is causing errors if charset is preset in the content-type header
                var response = await client.PostAsync(url, content);
                response.ThrowForHttpFailure();
                var responseBody = await response.Content.ReadAsStringAsync();
            }
        }
开发者ID:bernard357,项目名称:CaaSDeploy,代码行数:22,代码来源:ResourceDeployer.cs

示例11: TryParse


//.........这里部分代码省略.........
              case ICDBlockType.FreeText:
                var freetext = (DataBlock_FreeText)d;

                break;
              case ICDBlockType.Recipient:
                var recipient = (DataBlock_Recipient)d;

                break;
              case ICDBlockType.Synchronisation:
                var synchronisation = (DataBlock_Synchronisation)d;
                break;
              case ICDBlockType.DeviceIdentifier:
                var deviceIdentifier = (DataBlock_DeviceIdentifier)d;
                break;
              case ICDBlockType.Diagnostics:
                var diagnostics = (DataBlock_Diagnostics)d;
                break;
              case ICDBlockType.Sender:
                var sender = (DataBlock_Sender)d;
                break;
              case ICDBlockType.RegionCircle:
                var regionCircle = (DataBlock_Circle)d;
                break;
              case ICDBlockType.RegionPolygon:
                var regionPolygon = (DataBlock_Polygon)d;
                break;
              case ICDBlockType.PortalStatus:
                var portalStatus = (DataBlock_PortalStatus)d;
                break;
              case ICDBlockType.PhoneSettings:
                var phoneSettings = (DataBlock_PhoneSettings)d;
                //JObject jsonPhoneSettings = JObject.FromObject(phoneSettings);
                JObject jsonPhoneSettings = new JObject();
                jsonPhoneSettings.AddFirst(phoneSettings.BlockType.ToString());
                jsonPhoneSettings.First.AddAfterSelf(phoneSettings.ReportingFrecuencyRate);
                //jsonPhoneSettings.Add("type", phoneSettings.BlockType.ToString());
                jsonPhoneSettings.Add("ReportFrecuencyRate",phoneSettings.ReportingFrecuencyRate);
                jsonPhoneSettings.Add("type", phoneSettings.BlockType.ToString());
                 //jsonPhoneSettings.Add("Report",);

                report.Data.Add(jsonPhoneSettings);
                break;
              case ICDBlockType.GeofenceStatus:
                var geofenceStatus = (DataBlock_GeofenceStatus)d;
                break;
              case ICDBlockType.CannedMessagesHash:
                var cannedMessageHash = (DataBlock_CannedMessagesHash)d;
                JObject jsonCannedMessagesHash = JObject.FromObject(cannedMessageHash);
                jsonCannedMessagesHash.Add("type", cannedMessageHash.BlockType.ToString());
                report.Data.Add(jsonCannedMessagesHash);
                break;
              case ICDBlockType.PortalProviderInformation:
                var portalProviderInfo = (DataBlock_PortalProviderInformation)d;
                break;
              case ICDBlockType.ReducedSizeLocation:
                var reducedSizeLocation = (DataBlock_ReducedLocation)d;
                break;
              case ICDBlockType.CannedMessageIdentifier:
                var cannedMessageIdentifier = (DataBlock_CannedMessageIdentifier)d;
                break;
              case ICDBlockType.DistributionListHash:
                var distributionList = (DataBlock_DistributionListHash)d;
                break;
              case ICDBlockType.MessageIdentifier:
                var messageIdentifier = (DataBlock_MessageIdentifier)d;
                break;
开发者ID:jemc771,项目名称:IRIEXTREME,代码行数:67,代码来源:IridiumExtremeReport.cs

示例12: ExportScene

    private static string ExportScene(string scenePath)
    {
        var rig3DAssetAttr = typeof(Rig3DAssetAttribute);

        // Get a list of all classes annotated with AssetTypeAttribute
        var assetTypes =
            from t in rig3DAssetAttr.Assembly.GetTypes()
            let attr = t.GetCustomAttributes(rig3DAssetAttr, false)
            where attr.Any()
            select new
            {
                Type = t,
                Attr = attr.First() as Rig3DAssetAttribute,
            };

        var assetMap = new Dictionary<Mesh, MeshData>();
        FindMeshes(ref assetMap);

        var json = new JObject();
        var counters = new JObject();

        // Add annotated types
        foreach (var assetTypeInfo in assetTypes)
        {
            var array = GetAssetArray(assetTypeInfo.Type, assetTypeInfo.Attr.Exports);
            json.Add(assetTypeInfo.Attr.Name, array);
            counters.Add(assetTypeInfo.Attr.Name, array.Count);
        }

        // Add transform collections
        Bounds? bounds = null;
        var collections = Object.FindObjectsOfType<Rig3DCollection>();
        foreach (var collection in collections)
        {
            // special case for static meshes!!!
            if (collection.IsStaticMesh)
            {
                AddCollectionToMeshArray(collection, ref assetMap);
                continue;
            }

            var data = GetCollectionArray(collection);
            json.Add(collection.CollectionName, data.Collection);
            counters.Add(collection.CollectionName, data.Collection.Count);

            if (collection.CalculateBounds)
            {
                if (!bounds.HasValue)
                {
                    bounds = data.Bounds;
                }
                else
                {
                    var b = bounds.Value;
                    b.Encapsulate(data.Bounds);
                    bounds = b;
                }
            }
        }

        // add static mesh groups to the json
        var staticMeshes = new JObject();
        var staticMeshCounter = 0;
        foreach (var meshData in assetMap.Values)
        {
            if (!meshData.Instances.Any())
            {
                continue;
            }

            staticMeshes.Add(meshData.Name, meshData.Instances);
            staticMeshCounter += meshData.Instances.Count;
        }

        json.Add("staticMeshes", staticMeshes);
        counters.Add("staticMeshes", staticMeshCounter);

        // add level general metadata
        var metadata = new JObject();

        if (bounds.HasValue)
        {
            var center = bounds.Value.center;
            var size = bounds.Value.size;

            center.z = 0;
            size.z = 1;

            metadata.Add("bounds", ToJToken(new Bounds(center, size)));

            var dbg = GameObject.Find("__Debug") ?? new GameObject("__Debug");
            var debugBounds = dbg.GetComponent<DebugBounds>() ?? dbg.AddComponent<DebugBounds>();

            debugBounds.bounds.center = center;
            debugBounds.bounds.size = size;
        }

        metadata.Add("count", counters);

        json.AddFirst(new JProperty("metadata", metadata));
//.........这里部分代码省略.........
开发者ID:igm-capstone,项目名称:capstone-game-unity,代码行数:101,代码来源:AssetPipelineTools.cs


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