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


C# JToken.ToString方法代码示例

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


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

示例1: CreateUser

        protected UserInfo CreateUser(JToken obj)
        {
            if (obj["type"] == null)
            {
                throw new ApiException("Invalid json. No user type found.", ApiErrorType.Unknown);
            }

            var type = obj["type"].Value<string>();

            try
            {
                switch (type)
                {
                    case PartnerUser.PartnerUserTypeName:
                        return JsonConvert.DeserializeObject<PartnerUser>(obj.ToString());
                    case AgencyDirector.agencyDirectorTypeName:
                        return JsonConvert.DeserializeObject<AgencyDirector>(obj.ToString());
                    case AgencyConsultant.agencyConsultantTypeName:
                        return JsonConvert.DeserializeObject<AgencyConsultant>(obj.ToString());
                    case CompanyUser.companyUserTypeName:
                        return JsonConvert.DeserializeObject<CompanyUser>(obj.ToString());

                    default:
                        throw new ApiException("User type not implemented.", ApiErrorType.Unknown);
                }
            }
            catch (Exception ex)
            {
                throw new ApiException(string.Format("Could not parse user type: {0}", type), ApiErrorType.Unknown, ex.InnerException);
            }
        }
开发者ID:foretagsplatsen,项目名称:Foretagsplatsen-DotNet-API,代码行数:31,代码来源:UserBaseResource.cs

示例2: GetFormattedValue

        private static string GetFormattedValue(JToken val)
        {
            var output = val.ToString();

            if (val.Type == JTokenType.String)
            {
                // Replace quotes (") as escaped quotes ("")
                var escaped = val.ToString().Replace("\"", "\"\"");

                // All string are quoted
                output = String.Format("\"{0}\"", escaped);
            }
            return output;
        }
开发者ID:CoastalResilienceNetwork,项目名称:GeositeFramework,代码行数:14,代码来源:CsvHelper.cs

示例3: InitAsync

 public async Task<RedditUser> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     await JsonConvert.PopulateObjectAsync(json["name"] == null ? json["data"].ToString() : json.ToString(), this,
         reddit.JsonSerializerSettings);
     return this;
 }
开发者ID:haroldma,项目名称:RedditSharp,代码行数:7,代码来源:RedditUser.cs

示例4: CreateString

 public static string CreateString(JToken token)
 {
     if (token != null)
         return token.ToString();
     else
         return String.Empty;
 }
开发者ID:babelshift,项目名称:SteamWebAPI,代码行数:7,代码来源:TypeHelper.cs

示例5: CreateLong

 public static long CreateLong(JToken token)
 {
     if (token != null)
         return CreateLong(token.ToString());
     else
         return 0;
 }
开发者ID:babelshift,项目名称:SteamWebAPI,代码行数:7,代码来源:TypeHelper.cs

示例6: InitAsync

 public async new Task<AuthenticatedUser> InitAsync(Reddit reddit, JToken json, IWebAgent webAgent)
 {
     CommonInit(reddit, json, webAgent);
     await Task.Factory.StartNew(() => JsonConvert.PopulateObject(json["name"] == null ? json["data"].ToString() : json.ToString(), this,
         reddit.JsonSerializerSettings));
     return this;
 }
开发者ID:j1xwnbsr,项目名称:HFYBotReborn,代码行数:7,代码来源:AuthenticatedUser.cs

示例7: DeserializeWrapper

        /// <summary>
        /// Deserializes the specified value.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        internal static UserIdCollection DeserializeWrapper(JToken value)
        {
            if (value == null || (value is JObject && value.SelectToken("ids") == null))
                return null;

            decimal[] parsedIds;
            UserIdCollection result = new UserIdCollection();
            
            if (value is JArray)
            {
                parsedIds = JsonConvert.DeserializeObject<decimal[]>(value.ToString());
            }
            else
            {
                parsedIds = JsonConvert.DeserializeObject<decimal[]>(value.SelectToken("ids").ToString());

                result.NextCursor = value.SelectToken("next_cursor").Value<long>();
                result.PreviousCursor = value.SelectToken("previous_cursor").Value<long>();
            }
            
            foreach (decimal t in parsedIds)
            {
                result.Add(t);
            }

            return result;
        }
开发者ID:zippy1981,项目名称:Twitterizer,代码行数:32,代码来源:UserIdCollection.cs

示例8: VisitPrimitive

 private void VisitPrimitive(JToken data)
 {
     string key = this._currentPath;
     if (this._data.ContainsKey(key))
         throw new FormatException("Key is duplicated $((object) key))");
     this._data[key] = data.ToString();
 }
开发者ID:antonyfrancis,项目名称:simple-config-service,代码行数:7,代码来源:CustomJsonConfigurationFileParser.cs

示例9: UpdateProperty

        public static async Task UpdateProperty(this Cloud cloud, string property, JToken value, bool stayOnCloud = false)
        {
            var currentIndex = Main.Instance.Clouds.SelectedIndex;

            var o = @"{""cloud"":{""[:p]"":""[:v]""}}"
               .Replace("[:p]", property)
               .Replace("[:v]", value.ToString());
            Console.WriteLine(o);

            var client = new HttpClient
            {
                DefaultRequestHeaders =
                {
                    {"X-Auth-Token", App.Connection.SessionController.CurrentSession.AuthToken}
                }
            }.AcceptsJson();
            var response = await client.PostAsync(Endpoints.Cloud.Replace("[:id]", cloud.Id), new JsonContent(o));
            Console.WriteLine(await response.Content.ReadAsStringAsync());
            var responseObject = JsonConvert.DeserializeObject<WebResponse<Cloud>>(await response.Content.ReadAsStringAsync());

            if (responseObject.Flash != null)
            {
                App.Connection.NotificationController.Notification.Notify(responseObject.Flash.Message);
                return;
            }
            responseObject.Result.CopyTo(App.Connection.MessageController[cloud].Cloud);
            App.Connection.SessionController.RefreshClouds();
            Main.Instance.InitSession();

            if (stayOnCloud != true) return;
            Main.Instance.Clouds.SelectedIndex = currentIndex;
        }
开发者ID:Conji,项目名称:Cloudsdale-Win7,代码行数:32,代码来源:ModelHelpers.cs

示例10: ConvertValue

		private object ConvertValue(JToken value)
		{
			switch (value.Type)
			{
				case JTokenType.Integer:
					return value.ToObject<int>();

				case JTokenType.Float:
					return value.ToObject<double>();

				case JTokenType.Boolean:
					return value.ToObject<bool>();

				case JTokenType.Date:
					return value.ToObject<DateTime>();

				case JTokenType.Guid:
					return value.ToObject<Guid>();

				case JTokenType.TimeSpan:
					return value.ToObject<TimeSpan>();

				default:
					return value.ToString();
			}
		}
开发者ID:chimpinano,项目名称:MvcRouteTester,代码行数:26,代码来源:JsonBodyReader.cs

示例11: getChildObject

 public static Object getChildObject(JToken jtoken)
 {
     if (jtoken.Type == JTokenType.Object)
     {
         Hashtable hs = new Hashtable();
         foreach (KeyValuePair<string, JToken> token in (JObject)jtoken)
         {
             JToken token1 = token.Value;
             Object a = getChildObject(token1);
             hs.Add(token.Key, a);
         }
         return hs;
     }
     else if (jtoken.Type == JTokenType.Boolean)
     {
         return (Boolean)jtoken;
     }
     else if (jtoken.Type == JTokenType.String)
     {
         return jtoken.ToString();
     }
     else if (jtoken.Type == JTokenType.Array)
     {
         ArrayList list = new ArrayList();
         foreach (JToken token1 in (JArray)jtoken)
         {
             Object a = getChildObject(token1);
             list.Add(a);
         }
         return list;
     }
     return null;
 }
开发者ID:JasonDevStudio,项目名称:IBTS_WORD,代码行数:33,代码来源:JsonUtil.cs

示例12: OnMessage

	void OnMessage (int from, JToken data) {
		//Log to on-screen Console
		logWindow.text = logWindow.text.Insert (0, "Incoming message from device: " + from + ": " + data.ToString () + " \n \n");
		
		// Rotate the AirConsole Logo to the right
		if ((string)data == "left") {
			turnLeft = true;
			turnRight = false;
		}

		// Rotate the AirConsole Logo to the right
		if ((string)data == "right") {
			turnLeft = false;
			turnRight = true;
		}

		// Stop rotating the AirConsole Logo
		//'stop' is sent when a button on the controller is released
		if ((string)data == "stop") {
			turnLeft = false;
			turnRight = false;
		}

		//Show an Ad
		if ((string)data == "show_ad") {
			AirConsole.instance.ShowAd ();
		}
	}
开发者ID:AirConsole,项目名称:airconsole-unity-plugin,代码行数:28,代码来源:ExampleBasicLogic.cs

示例13: ParseItem

        public static FileMappingItem ParseItem(JToken item)
        {
            if (item.Type == JTokenType.Object)
            {
                return JsonConvert.DeserializeObject<FileMappingItem>(item.ToString());
            }
            else if (item.Type == JTokenType.Property)
            {
                JProperty jProperty = item as JProperty;
                FileMappingItem model = new FileMappingItem { Name = jProperty.Name };
                var value = jProperty.Value;
                if (value.Type == JTokenType.Array)
                {
                    model.Files = new FileItems(value.Select(s => s.Value<string>()));
                }
                else if (value.Type == JTokenType.String)
                {
                    model.Files = new FileItems((string)value);
                }
                else
                {
                    throw new JsonReaderException(string.Format("Unsupported value {0} (type: {1}).", value, value.Type));
                }

                return model;
            }
            else if (item.Type == JTokenType.String)
            {
                return new FileMappingItem { Files = new FileItems(item.Value<string>()) };
            }
            else
            {
                throw new JsonReaderException(string.Format("Unsupported value {0} (type: {1}).", item, item.Type));
            }
        }
开发者ID:yodamaster,项目名称:docfx,代码行数:35,代码来源:FileModelParser.cs

示例14: ConfigurationDataNCore

        public ConfigurationDataNCore(JToken json)
        {
            ConfigurationDataNCore configData = new ConfigurationDataNCore();

            dynamic configArray = JsonConvert.DeserializeObject(json.ToString());
            foreach (var config in configArray)
            {
                string propertyName = UppercaseFirst((string)config.id);
                switch (propertyName)
                {
                    case "Username":
                        Username = new StringItem { Name = propertyName, Value = config.value };
                        break;
                    case "Password":
                        Password = new StringItem { Name = propertyName, Value = config.value };
                        break;
                    case "Hungarian":
                        Hungarian = new BoolItem { Name = propertyName, Value = config.value };
                        break;
                    case "English":
                        English = new BoolItem { Name = propertyName, Value = config.value };
                        break;
                    default:
                        break;
                }
            }
        }
开发者ID:CatmanIX,项目名称:Shades,代码行数:27,代码来源:ConfigurationDataNCore.cs

示例15: CreateBoolean

 public static bool CreateBoolean(JToken token)
 {
     if (token != null)
         return CreateBoolean(token.ToString());
     else
         return false;
 }
开发者ID:babelshift,项目名称:SteamWebAPI,代码行数:7,代码来源:TypeHelper.cs


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