本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.ToString方法的具体用法?C# JObject.ToString怎么用?C# JObject.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JObject
的用法示例。
在下文中一共展示了JObject.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemListStatic
public ItemListStatic(JObject basicO,
JObject dataO,
JArray groupsA,
JArray treeA,
string type,
string version,
JObject originalObject)
{
data = new Dictionary<string, ItemStatic>();
groups = new List<GroupStatic>();
tree = new List<ItemTreeStatic>();
if (basicO != null)
{
basic = HelperMethods.LoadBasicDataStatic(basicO);
}
if (dataO != null)
{
LoadData(dataO.ToString());
}
if (groupsA != null)
{
LoadGroups(groupsA);
}
if (treeA != null)
{
LoadTree(treeA);
}
this.type = type;
this.version = version;
this.originalObject = originalObject;
}
示例2: BetRequest
public static int BetRequest(JObject jsonState)
{
int bet = 0;
var gameState = JsonConvert.DeserializeObject<GameState>(jsonState.ToString());
try
{
string actualDecision = "none";
Logger.LogHelper.Log("type=bet_begin action=bet_request request_id={0} game_id={1}", requestId, gameState.GameId);
foreach (IDecisionLogic decisionLogic in Decisions.DecisionFactory.GetDecisions())
{
//végigpróbáljuk a lehetőségeket
int? possibleBet = decisionLogic.MakeADecision(gameState);
if (possibleBet.HasValue)
{
bet = possibleBet.Value;
actualDecision = decisionLogic.GetName();
break;
}
}
string cards = String.Join(",", gameState.OwnCards);
Logger.LogHelper.Log("type=bet action=bet_request request_id={0} game_id={1} bet={2} cards={3} decision={4}",
requestId, gameState.GameId, bet, cards, actualDecision);
}
catch (Exception ex)
{
Logger.LogHelper.Error("type=error action=bet_request request_id={0} game_id={1} error_message={2}",requestId, gameState.GameId, ex);
}
return bet;
}
示例3: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
var obj = new JObject(new JProperty("machineName", ServerManager.MachineName), new JProperty("servers", JArray.FromObject(ServerManager.GetActiveServerList())));
Response.BinaryWrite(Encoding.UTF8.GetBytes(obj.ToString()));
Response.End();
}
示例4: VerifyEnum
public void VerifyEnum()
{
Type typeToTest = typeof(Duplex);
var typeExpected = new JObject(new JProperty("type", "#/Duplex")).ToString();
var schemaExpected = new JObject(
new JProperty("Duplex",
new JObject(
new JProperty("id", "#/Duplex"),
new JProperty("type", "number"),
new JProperty("enum", new JArray(1, 2, 3, -1)),
new JProperty("options", new JArray(
new JObject(new JProperty("value", 1), new JProperty("label", "Simplex")),
new JObject(new JProperty("value", 2), new JProperty("label", "Vertical")),
new JObject(new JProperty("value", 3), new JProperty("label", "Horizontal")),
new JObject(new JProperty("value", -1), new JProperty("label", "Default"))
))))
).ToString();
const bool flatten = false;
var schema = new JObject();
string actual = GetActual(typeToTest, typeExpected, flatten, schema);
Assert.AreEqual(typeExpected, actual);
Console.WriteLine("SCHEMA\n" + schema.ToString(Formatting.Indented));
Assert.AreEqual(schemaExpected, schema.ToString(Formatting.Indented));
}
示例5: DismissShow
public virtual DismissMovieResult DismissShow(string apiKey, string username, string passwordHash, string imdbId = null, int? tvdbId = null, string title = null, int? year = null)
{
var url = String.Format("{0}{1}", Url.RecommendationsShowsDismiss, apiKey);
var postJson = new JObject();
postJson.Add(new JProperty("username", username));
postJson.Add(new JProperty("password", passwordHash));
if (imdbId != null)
postJson.Add(new JProperty("imdb_id", imdbId));
if (tvdbId != null)
postJson.Add(new JProperty("tvdb_id", tvdbId));
if (title != null)
postJson.Add(new JProperty("title", title));
if (year != null)
postJson.Add(new JProperty("year", year));
var responseJson = _httpProvider.DownloadString(url, postJson.ToString());
if (String.IsNullOrWhiteSpace(responseJson))
return null;
return JsonConvert.DeserializeObject<DismissMovieResult>(responseJson);
}
示例6: VerifyFlagsEnum
public void VerifyFlagsEnum()
{
Type typeToTest = typeof(PaletteFlags);
var typeExpected = new JObject(
new JProperty("type", "#/PaletteFlags")
).ToString();
var schemaExpected = new JObject(
new JProperty("PaletteFlags",
new JObject(new JProperty("id", "#/PaletteFlags"),
new JProperty("type", "number"),
new JProperty("format", "bitmask"),
new JProperty("enum", new JArray(1, 2, 4)),
new JProperty("options", new JArray(
new JObject(new JProperty("value", 1), new JProperty("label", "HasAlpha")),
new JObject(new JProperty("value", 2), new JProperty("label", "GrayScale")),
new JObject(new JProperty("value", 4), new JProperty("label", "Halftone"))
))))
).ToString();
const bool flatten = false;
var schema = new JObject();
string actual = GetActual(typeToTest, typeExpected, flatten, schema);
Assert.AreEqual(typeExpected, actual);
Console.WriteLine("SCHEMA\n" + schema.ToString(Formatting.Indented));
Assert.AreEqual(schemaExpected, schema.ToString(Formatting.Indented));
}
示例7: ReadJson
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
string[] props = new string[] { "EntryId", "DateCreated", "CreatedBy", "DateUpdated", "UpdatedBy" };
JObject orig = JObject.Load(reader);
JObject result = new JObject();
JObject responses = new JObject();
foreach (string p in props)
{
result[p] = orig[p];
orig.Remove(p);
}
foreach (var prop in orig.Properties())
{
responses[prop.Name] = prop.Value;
}
result.Add("Fields", responses);
var outString = result.ToString();
Entry e = new Entry();
JsonConvert.PopulateObject(result.ToString(), e);
return e;
}
示例8: ProcessRequestAsyncSuccessfully
public void ProcessRequestAsyncSuccessfully()
{
JObject returnValue = new JObject { { "Name", "TestName" } };
Uri requestUri =
new Uri(
string.Format(
"http://bla.com/api/{0}/{1}?{2}=TestValue1",
WebApiConfiguration.Instance.Apis[0].Name,
WebApiConfiguration.Instance.Apis[0].WebMethods[0].Name,
WebApiConfiguration.Instance.Apis[0].WebMethods[0].Parameters[0].Name));
Mock<IRunner> runnerMock = new Mock<IRunner>(MockBehavior.Strict);
runnerMock.Setup(
m => m.ExecuteAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<IList<KeyValuePair<string, string>>>(), It.IsAny<bool>()))
.ReturnsAsync(new PowershellReturn
{
PowerShellReturnedValidData = true,
ActualPowerShellData = returnValue.ToString()
});
var ioc = createContainer(cb => cb.RegisterInstance(runnerMock.Object));
var genericController = ioc.Resolve<GenericController>();
genericController.Request = new HttpRequestMessage(HttpMethod.Get, requestUri);
var res = genericController.ProcessRequestAsync().Result;
Assert.AreEqual(
returnValue.ToString(),
res.Content.ReadAsStringAsync().Result,
"Return value from process request is incorrect");
}
示例9: Button_Click_1
//post方式调用服务器接口
private void Button_Click_1(object sender, RoutedEventArgs e)
{
//填写查寻密钥
string queryKey = "abc";
//定义要访问的云平台接口--接口详见服务器开发文档
string uri="/api/20140928/management";
DateTime Jan1st1970 = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long Sticks = (long)(DateTime.UtcNow - Jan1st1970).TotalMilliseconds;
string timeStamp = Sticks.ToString();
//填写服务器提供的服务码
string queryString = "service_code=TESTING";
WoanSignature.Signature Signature = new WoanSignature.Signature();
//定义请求数据,以下json是一个删除文件的json请求
JObject json = new JObject(
new JProperty("function", "delete_video"),
new JProperty("params",
new JObject(
new JProperty("service_code", "TESTING"),
new JProperty("file_name", "1.m3u8")
)
)
);
string signature = Signature.SignatureForPost(uri, queryKey, queryString, json.ToString(), timeStamp);
WoanSignature.HttpTool HttpTool = new WoanSignature.HttpTool();
string response = HttpTool.post("http://c.zhiboyun.com/api/20140928/management?" + queryString, signature, timeStamp, json.ToString());
MessageBox.Show(response);
}
示例10: SendMessage
public void SendMessage(string targetId, string senderId, JObject jobj, ConversationType type)
{
if (type == ConversationType.PRIVATE)
{
int messageId = Rcsdk.SaveMessage(targetId, 1, "RC:TxtMsg", senderId, jobj.ToString(), "", "", false, 0);
Rcsdk.sendMessage(targetId, 1, 2, "RC:TxtMsg", jobj.ToString(), "", "", messageId, _sendCallBack);
}
else if (type == ConversationType.DISCUSSION)
{
int messageId1 = Rcsdk.SaveMessage(targetId, 2, "RC:TxtMsg", senderId, jobj.ToString(), "", "", false, 0);
Rcsdk.sendMessage(targetId, 2, 3, "RC:TxtMsg", jobj.ToString(), "", "", messageId1, _sendCallBack);
}
}
示例11: invalidParams_platform
public void invalidParams_platform() {
JObject payload = new JObject();
payload.Add("platform", JToken.FromObject("all_platform"));
payload.Add("audience", JToken.FromObject(JsonConvert.SerializeObject(Audience.all(), new AudienceConverter())));
payload.Add("notification", JToken.FromObject(new Notification().setAlert(ALERT)));
Console.WriteLine("json string: " + payload.ToString());
try {
var result = _client.SendPush(payload.ToString());
} catch (APIRequestException e) {
Assert.AreEqual(INVALID_PARAMS, e.ErrorCode);
}
}
示例12: GetItemRankings
public List<ItemRecommendation> GetItemRankings(string userId, string[] itemIds)
{
if (!itemIds.Any())
{
throw new InvalidOperationException("Must have at least one itemId");
}
var request = new JObject();
request[Constants.UserId] = userId;
var jItems = new JArray();
foreach (var itemId in itemIds)
{
jItems.Add(itemId);
}
request[Constants.ItemIds] = jItems;
var body = request.ToString(Formatting.None);
var response = (JObject)Execute(Constants.EngineResource, Method.POST, body);
if (response[Constants.IsOriginal].Value<bool>())
{
return new List<ItemRecommendation>();
}
var recommendations = new List<ItemRecommendation>();
foreach (var item in response[Constants.Items])
{
var property = item.First.Value<JProperty>();
var recommendation = new ItemRecommendation
{
ItemId = property.Name,
Score = item.First.First.Value<float>()
};
recommendations.Add(recommendation);
}
return recommendations;
}
示例13: makeRequestForm
public RequestForm makeRequestForm(JObject json)
{
string currManagerName = (string)json["current"]["bazookaInfo"]["managerId"];
string futureManagerName = (string)json["future"]["bazookaInfo"]["managerId"];
int managerID = GetIDFromName(currManagerName);
int f_managerID = GetIDFromName(futureManagerName);
json["current"]["bazookaInfo"]["managerId"] = managerID;
json["current"]["ultiproInfo"]["supervisor"] = managerID;
json["future"]["bazookaInfo"]["managerId"] = f_managerID;
json["future"]["ultiproInfo"]["supervisor"] = f_managerID;
UserController uc = new UserController();
string[] name = uc.GetUserName().Split('.');
string creatorName = name[0] + " " + name[1];
int creatorID = GetIDFromName(creatorName);
RequestForm obj = null;
using (var sr = new StringReader(json.ToString()))
using (var jr = new JsonTextReader(sr))
{
var js = new JsonSerializer();
obj = (RequestForm)js.Deserialize<RequestForm>(jr);
}
obj.EmployeeId = GetIDFromName((string)json["name"]);
obj.CreatedByID = creatorID;
obj.Current.BazookaInfo.SecurityItemRights = "";
obj.ReviewInfo.FilesToBeRemovedFrom = "(" + obj.Current.BazookaInfo.Group + ")" + currManagerName.Replace(" ", ".")+" "+obj.ReviewInfo.FilesToBeRemovedFrom;
obj.ReviewInfo.FilesToBeAddedTo = "(" + obj.Future.BazookaInfo.Group + ")" + futureManagerName.Replace(" ", ".")+" "+obj.ReviewInfo.FilesToBeAddedTo;
return obj;
}
示例14: DataReceived
public void DataReceived(JObject data)
{
if (data["msg"] != null)
{
switch (data["msg"].ToString())
{
case "connected":
// stuff that occurs on connection such as subscription if desired
//this.Subscribe("requests");
break;
case "added":
Console.WriteLine("Document Added: " + data["id"]);
break;
case "ready":
Console.WriteLine("Subscription Ready: " + data["subs"].ToString());
break;
case "removed":
Console.WriteLine("Document Removed: " + data["id"]);
break;
default:
Console.WriteLine(data.ToString());
break;
}
}
}
示例15: invalidParams_audience
public void invalidParams_audience()
{
JObject payload = new JObject();
payload.Add("platform", JToken.FromObject(JsonConvert.SerializeObject(Platform.all(), new PlatformConverter())));
payload.Add("audience", JToken.FromObject("all_audience"));
JsonSerializer jsonSerializer = new JsonSerializer();
jsonSerializer.DefaultValueHandling = DefaultValueHandling.Ignore;
payload.Add("notification", JToken.FromObject(new Notification().setAlert(ALERT), jsonSerializer));
Console.WriteLine("json string: " + payload.ToString());
try {
var result = _client.SendPush(payload.ToString());
}catch (APIRequestException e) {
Assert.AreEqual(INVALID_PARAMS, e.ErrorCode);
}
}