本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例4: CreateString
public static string CreateString(JToken token)
{
if (token != null)
return token.ToString();
else
return String.Empty;
}
示例5: CreateLong
public static long CreateLong(JToken token)
{
if (token != null)
return CreateLong(token.ToString());
else
return 0;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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();
}
}
示例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;
}
示例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 ();
}
}
示例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));
}
}
示例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;
}
}
}
示例15: CreateBoolean
public static bool CreateBoolean(JToken token)
{
if (token != null)
return CreateBoolean(token.ToString());
else
return false;
}