本文整理汇总了C#中JsonObject.Add方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.Add方法的具体用法?C# JsonObject.Add怎么用?C# JsonObject.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("http://api.chronojump.org:8080/ping");
// Set the Method property of the request to POST.
request.Method = "POST";
// Set the ContentType property of the WebRequest.
request.ContentType = "application/json";
// Creates the json object
JsonObject json = new JsonObject();
json.Add("os_version", "Linux");
json.Add("cj_version", "0.99");
// Converts it to a String
String js = json.ToString();
// Writes the json object into the request dataStream
Stream dataStream = request.GetRequestStream ();
dataStream.Write (Encoding.UTF8.GetBytes(js), 0, js.Length);
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status (will be 201, CREATED)
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Clean up the streams.
dataStream.Close ();
response.Close ();
}
示例2: SuccessCallback
protected override void SuccessCallback(MessageStructure writer, MessageHead head)
{
int type = writer.ReadInt();
if (type == 1)
{
int recordCount = writer.ReadInt();
JsonObject jsonContainer = new JsonObject();
List<JsonObject> jsonList = new List<JsonObject>();
for (int i = 0; i < recordCount; i++)
{
writer.RecordStart();
var item = new JsonObject();
item.Add("NoticeID", writer.ReadString());
item.Add("Title", writer.ReadString());
item.Add("Content", writer.ReadString());
item.Add("IsBroadcast", writer.ReadInt());
item.Add("IsTop", writer.ReadInt());
item.Add("Creater", writer.ReadString());
item.Add("CreateDate", writer.ReadString());
item.Add("ExpiryDate", writer.ReadString());
jsonList.Add(item);
writer.RecordEnd();
}
jsonContainer.Add("total", recordCount);
jsonContainer.Add("rows", jsonList.ToArray());
WriteTableJson(jsonContainer);
}
}
示例3: LoadAboutData
private async void LoadAboutData(string hash)
{
var httpclient = new Windows.Web.Http.HttpClient();
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
var time = Convert.ToInt64(ts.TotalMilliseconds).ToString();
var key = Class.MD5.GetMd5String("1005Ilwieks28dk2k092lksi2UIkp8150" + time);
var postobj = new JsonObject();
postobj.Add("appid", JsonValue.CreateStringValue("1005"));
postobj.Add("mid", JsonValue.CreateStringValue(""));
postobj.Add("clientver", JsonValue.CreateStringValue("8150"));
postobj.Add("clienttime", JsonValue.CreateStringValue("1469035332000"));
postobj.Add("key", JsonValue.CreateStringValue("27b498a7d890373fadb673baa1dabf7e"));
var array = new JsonArray();
var videodata = new JsonObject();
videodata.Add("video_hash", JsonValue.CreateStringValue(hash));
videodata.Add("video_id", JsonValue.CreateNumberValue(0));
array.Add(videodata);
postobj.Add("data", array);
var postdata = new Windows.Web.Http.HttpStringContent(postobj.ToString());
var result= await httpclient.PostAsync(new Uri("http://kmr.service.kugou.com/v1/video/related"), postdata);
var json = await result.Content.ReadAsStringAsync();
json = json.Replace("{size}", "150");
var obj = JsonObject.Parse(json);
AboutMVListView.ItemsSource = Class.data.DataContractJsonDeSerialize<List<AboutMVdata>>(obj.GetNamedArray("data")[0].GetArray().ToString());
}
示例4: Generate
internal static JsonObject Generate(Comment comment, ServerInfo serverInfo)
{
var json = new JsonObject();
if (comment.Body != null)
{
json.Add("body", comment.Body);
}
if (comment.Visibility != null)
{
if (serverInfo.BuildNumber >= ServerVersionConstants.BuildNumberJira43)
{
var visibilityJson = new JsonObject();
var commentVisibilityType = comment.Visibility.Type == Visibility.VisibilityType.Group ? "group" : "role";
if (serverInfo.BuildNumber < ServerVersionConstants.BuildNumberJira5)
{
commentVisibilityType = commentVisibilityType.ToUpper();
}
visibilityJson.Add("type", commentVisibilityType);
visibilityJson.Add("value", comment.Visibility.Value);
json.Add("visibility", visibilityJson.ToJson());
}
else
{
json.Add(comment.Visibility.Type == Visibility.VisibilityType.Role ? "role" : "group", comment.Visibility.Value);
}
}
return json;
}
示例5: ToJson
public static JsonObject ToJson(Dominion.GameDescription gameDescription, int starRating)
{
JsonObject root = new Windows.Data.Json.JsonObject();
root.Add(jsonNameDeck, ToJson(gameDescription));
JsonArray expansionArray = new JsonArray();
Dominion.Expansion[] presentExpansions;
Dominion.Expansion[] missingExpansions;
gameDescription.GetRequiredExpansions(out presentExpansions, out missingExpansions);
foreach (var expansion in presentExpansions)
{
JsonObject expansionObject = new JsonObject();
expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName()));
expansionObject.Add("present", JsonValue.CreateBooleanValue(true));
expansionArray.Add(expansionObject);
}
foreach (var expansion in missingExpansions)
{
JsonObject expansionObject = new JsonObject();
expansionObject.Add("name", JsonValue.CreateStringValue(expansion.ToProgramaticName()));
expansionObject.Add("present", JsonValue.CreateBooleanValue(false));
expansionArray.Add(expansionObject);
}
root.Add(jsonNameRequiredExpansions, expansionArray);
root.Add(jsonNameRating, JsonValue.CreateNumberValue(starRating));
return root;
}
示例6: serializeObject
private static JsonObject serializeObject(object obj)
{
PropertyInfo[] propInfo = obj.GetType().GetProperties();
string propertyName;
object propertyValue;
JsonValueType type;
JsonObject o = new JsonObject(propInfo.Length);
foreach (var p in propInfo)
{
propertyName = p.Name;
propertyValue = p.GetValue(obj);
type = JsonValue.GetPrimitiveType(p.PropertyType);
if (type == JsonValueType.Object)
{
JsonObject o2 = serializeObject(propertyValue);
o.Add(propertyName, o2);
continue;
}
else if (type == JsonValueType.Array)
{
JsonArray a = serializeArray((IEnumerable)propertyValue);
o.Add(propertyName, a);
continue;
}
else
{
string value = propertyValue.ToString();
JsonPrimitive primitive = new JsonPrimitive(value, type);
o.Add(propertyName, primitive);
}
}
return o;
}
示例7: Search
public async Task<string> Search(string search)
{
using (AutoResetEvent handle = new AutoResetEvent(false))
{
JsonObject message = new JsonObject();
message.Add("method", JsonValue.CreateStringValue("core.library.search"));
JsonObject queryObject = new JsonObject();
queryObject.Add("track_name", JsonValue.CreateStringValue(search));
JsonArray urisArray = new JsonArray();
urisArray.Add(JsonValue.CreateStringValue("spotify:"));
JsonObject paramsObject = new JsonObject();
paramsObject.Add("query", queryObject);
paramsObject.Add("uris", urisArray);
message.Add("params", paramsObject);
string result = null;
await Send(message, searchResult =>
{
JsonArray tracks = searchResult.GetNamedArray("result")[0].GetObject().GetNamedArray("tracks");
result = tracks.First().GetObject().GetNamedString("uri");
handle.Set();
});
handle.WaitOne(TimeSpan.FromSeconds(30));
return result;
}
}
示例8: OnClick
private async void OnClick(object sender, RoutedEventArgs e)
{
Button btn = sender as Button;
MessageDialog msgBox = new MessageDialog("请输入姓名、城市和年龄。");
if(txtName.Text == "" || txtCity.Text == "" || txtAge.Text == "")
{
await msgBox.ShowAsync();
return;
}
btn.IsEnabled = false;
// 获取文档库目录
StorageFolder doclib = KnownFolders.DocumentsLibrary;
// 将输入的内容转化为 json 对象
JsonObject json = new JsonObject();
json.Add("name", JsonValue.CreateStringValue(txtName.Text));
json.Add("city", JsonValue.CreateStringValue(txtCity.Text));
json.Add("age", JsonValue.CreateNumberValue(Convert.ToDouble(txtAge.Text)));
// 提取出 json 字符串
string jsonStr = json.Stringify();
// 在文档库中创建新文件
string fileName = DateTime.Now.ToString("yyyy-M-d-HHmmss") + ".mydoc";
StorageFile newFile = await doclib.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
// 将 json 字符串写入文件
await FileIO.WriteTextAsync(newFile, jsonStr);
btn.IsEnabled = true;
msgBox.Content = "保存成功";
await msgBox.ShowAsync();
}
示例9: Generate
internal static JsonObject Generate(WorklogInput worklogInput)
{
var json = new JsonObject
{
{ "self", worklogInput.Self.ToString() },
{ "comment", worklogInput.Comment },
{ "started", worklogInput.StartDate.ToRestString() },
{ "timeSpent", worklogInput.MinutesSpent.ToString() }
};
if (worklogInput.Visibility != null)
{
json.Add("visibility", VisibilityJsonGenerator.Generate(worklogInput.Visibility).ToJson());
}
if (worklogInput.Author != null)
{
json.Add("author", BasicUserJsonGenerator.Generate(worklogInput.Author).ToJson());
}
if (worklogInput.UpdateAuthor != null)
{
//json.Add("updateAuthor", BasicUserJsonGenerator.Generate(worklogInput.UpdateAuthor).ToString());
json.Add("updateAuthor", worklogInput.UpdateAuthor.ToJson());
}
return json;
}
示例10: ToJSON
public JsonObject ToJSON()
{
JsonObject temp = new JsonObject();
temp.Add("name", JsonValue.CreateStringValue(Name));
temp.Add("keyid", JsonValue.CreateStringValue(KeyID));
temp.Add("vcode", JsonValue.CreateStringValue(VCode));
return temp;
}
示例11: sendLoginRequest
public void sendLoginRequest(string username, string password, Action<string> successful, Action<string> failure)
{
JsonObject jsonRequest = new JsonObject ();
jsonRequest.Add (Constants.pUserName, CoreSystem.Utils.Encrypt (username));
jsonRequest.Add (Constants.pPassword, CoreSystem.Utils.Encrypt (password));
TCServices.sendLogin (jsonRequest, successful, failure);
}
示例12: ToJson
internal override JsonObject ToJson(out JsonObject properties)
{
var json = base.ToJson(out properties);
properties.Add("articleBody", JsonValue.CreateStringValue(ArticleBody ?? String.Empty));
properties.Add("articleSection", JsonValue.CreateStringValue(ArticleSection ?? String.Empty));
properties.Add("wordCount", JsonValue.CreateNumberValue(WordCount));
return json;
}
示例13: Secured
public JsonObject Secured()
{
var response = new JsonObject();
response.Add("UserId", AuthenticatedUserId.ToString());
response.Add("UserName", AuthenticatedUser.Identity.Name);
return response;
}
示例14: ConfigureInputArgs
protected void ConfigureInputArgs(JsonObject data)
{
// all the requests need an API key...
data.Add("apiKey", ApiKey);
// are we logged on?
if (StreetFooRuntime.HasLogonToken)
data.Add("logonToken", StreetFooRuntime.LogonToken);
}
示例15: ShouldReturnObjectMembers
public void ShouldReturnObjectMembers() {
var obj = new JsonObject();
var member = new JsonObject.JsonMember("name", "value");
obj.Add(member);
obj.Add(member);
var members = obj.Value;
Assert.That(members.Length, Is.EqualTo(2));
Assert.That(members[0], Is.EqualTo(member));
}