本文整理汇总了C#中JsonObject类的典型用法代码示例。如果您正苦于以下问题:C# JsonObject类的具体用法?C# JsonObject怎么用?C# JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonObject类属于命名空间,在下文中一共展示了JsonObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessSub
protected override void ProcessSub(HttpContext context, string uploadPath, string fileName)
{
JsonObject obj2 = new JsonObject();
obj2.Put("data", uploadPath + "T_" + fileName);
obj2.Put("success", true);
context.Response.Write(obj2.ToString());
}
示例2: Append
public override void Append(JsonSchemaRuleComponent rules, JsonObject definition, Func<JsonObject, JsonSchemaRule> parse)
{
if (definition.Contains<JsonTrue>("uniqueItems"))
{
rules.Add(new JsonUniqueItemsRule());
}
}
示例3: 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;
}
示例4: InvokeOnEvent
/// <summary>
/// If the event exists,invoke the event when server return messge.
/// </summary>
/// <param name="eventName"></param>
/// <param name="value"></param>
/// <returns></returns>
///
public void InvokeOnEvent(string route, JsonObject msg)
{
if(!this.eventMap.ContainsKey(route)) return;
List<Action<JsonObject>> list = eventMap[route];
foreach(Action<JsonObject> action in list) action.Invoke(msg);
}
示例5: AddRuleProduct
private string AddRuleProduct(HttpContext context)
{
JsonObject obj2 = new JsonObject();
int num = Convert.ToInt32(context.Request.Form["ProductId"]);
int ruleId = Convert.ToInt32(context.Request.Form["RuleId"]);
string str = context.Request.Form["ProductName"];
if (this.ruleProductBll.Exists(ruleId, (long) num))
{
obj2.Put("STATUS", "Presence");
return obj2.ToString();
}
Maticsoft.Model.Shop.Sales.SalesRuleProduct model = new Maticsoft.Model.Shop.Sales.SalesRuleProduct {
ProductId = num,
RuleId = ruleId,
ProductName = str
};
if (this.ruleProductBll.Add(model))
{
obj2.Put("STATUS", "SUCCESS");
obj2.Put("DATA", "Approve");
return obj2.ToString();
}
obj2.Put("STATUS", "NODATA");
return obj2.ToString();
}
示例6: DeleteBrands
private void DeleteBrands(HttpContext context)
{
JsonObject obj2 = new JsonObject();
string str = context.Request.Params["idList"];
if (!string.IsNullOrWhiteSpace(str))
{
Maticsoft.BLL.Shop.Products.BrandInfo info = new Maticsoft.BLL.Shop.Products.BrandInfo();
Maticsoft.BLL.Shop.Products.ProductInfo info2 = new Maticsoft.BLL.Shop.Products.ProductInfo();
Maticsoft.BLL.Shop.Products.ProductTypeBrand brand = new Maticsoft.BLL.Shop.Products.ProductTypeBrand();
int brandId = Globals.SafeInt(str, 0);
if (info2.ExistsBrands(brandId))
{
obj2.Put("STATUS", "FAILED");
obj2.Put("DATA", "该品牌正在使用中!");
}
if (info.DeleteList(str))
{
brand.Delete(null, new int?(brandId));
obj2.Put("STATUS", "SUCCESS");
}
else
{
obj2.Put("STATUS", "FAILED");
obj2.Put("DATA", "系统忙,请稍后再试!");
}
}
else
{
obj2.Put("STATUS", "FAILED");
obj2.Put("DATA", "系统忙,请稍后再试!");
}
context.Response.Write(obj2.ToString());
}
示例7: Parse
public static FacebookObject Parse(JsonObject obj) {
if (obj == null) return null;
return new FacebookObject(obj) {
Id = obj.GetString("id"),
Name = obj.GetString("name")
};
}
示例8: Run
public static void Run()
{
//TODO: Fix this up with a request wrapper
dynamic googleSearch = new RestClient(null, Services.GoogleSearchUri, RestService.Json);
Console.WriteLine("Searching Google for 'seattle'...");
dynamic searchOptions = new JsonObject();
searchOptions.q = "seattle";
dynamic search = googleSearch.invokeAsync(searchOptions);
search.Callback((RestCallback)delegate() {
dynamic results = search.Result.responseData.results;
foreach (dynamic item in results) {
Console.WriteLine(item.titleNoFormatting);
Console.WriteLine(item.url);
Console.WriteLine();
}
});
while (search.IsCompleted == false) {
Console.WriteLine(".");
Thread.Sleep(100);
}
}
示例9: Update
//note the async keyword - it's cause we're using an "await" method in our method body
public async void Update()
{
var client = new HttpClient();
//ooh fancy new await syntax!
//this actually executes in parallel and pauses the rest of the method's execution until it returns
//(in a non blocking way of course)
var result = await client.GetAsync(string.Format("http://search.twitter.com/search.json?q={0}&since_id={1}", SearchTerm, Since));
var root = new JsonObject(result.Content.ReadAsString());
var array = root.GetNamedArray("results");
for(int i = 0; i < array.Count; i++)
{
var element = array[i];
JsonObject obj = element.GetObject();
Tweet tweet = new Tweet
{
created_at = obj.GetNamedString("created_at"),
from_user = obj.GetNamedString("from_user"),
id_str = obj.GetNamedString("id_str"),
profile_image_url = obj.GetNamedString("profile_image_url"),
text = obj.GetNamedString("text")
};
if (!Tweets.Any(t => t.id_str == tweet.id_str))
{
Tweets.Insert(0, tweet);
}
}
}
示例10: CreateJsonTest
private void CreateJsonTest()
{
JsonArray weekDiet = new JsonArray();
for(int i=0;i<7;i++)
{
JsonObject diet = new JsonObject();
diet["DayNumber"] = i;
diet["Breakfast"] = "Banana"+ i;
diet["Lunch"] = "Banana"+ i;
diet["Dinner"] = "Banana"+ i;
diet["WithSugar"] = (i % 2 == 0);
diet["RandomNumber"] = Random.Range(0f,1.5f);
weekDiet.Add(diet);
}
for (int i=0;i<7;i++)
{
if (i % 2 == 1)
{
weekDiet[i]["RandomNumber"] = 3;
weekDiet[i]["RandomNumber"] = weekDiet[i]["RandomNumber"] * 2f;
}
}
Debug.Log("Test InputOutputFileTest done: \n"+ weekDiet.ToJsonPrettyPrintString());
}
示例11: GetCategoryInfo
public void GetCategoryInfo(HttpContext context)
{
Func<Maticsoft.Model.SNS.Categories, bool> predicate = null;
string categoryId = context.Request.Params["CID"];
int type = Globals.SafeInt(context.Request.Params["Type"], 0);
JsonObject obj2 = new JsonObject();
if (!string.IsNullOrWhiteSpace(categoryId))
{
if (predicate == null)
{
predicate = c => c.ParentID == Globals.SafeInt(categoryId, 0);
}
List<Maticsoft.Model.SNS.Categories> list2 = this.SNSCateBll.GetAllCateByCache(type).Where<Maticsoft.Model.SNS.Categories>(predicate).ToList<Maticsoft.Model.SNS.Categories>();
if ((list2 != null) && (list2.Count > 0))
{
JsonArray data = new JsonArray();
list2.ForEach(delegate (Maticsoft.Model.SNS.Categories info) {
data.Add(new JsonObject(new string[] { "CategoryId", "Name", "ParentID", "HasChildren" }, new object[] { info.CategoryId, info.Name, info.ParentID, info.HasChildren }));
});
obj2.Put("STATUS", "Success");
obj2.Put("DATA", data);
}
else
{
obj2.Put("STATUS", "Fail");
}
}
else
{
obj2.Put("STATUS", "Error");
}
context.Response.Write(obj2.ToString());
}
示例12: LoadState
/// <summary>
/// Populates the page with content passed during navigation. Any saved state is also
/// provided when recreating a page from a prior session.
/// </summary>
/// <param name="navigationParameter">The parameter value passed to
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
/// </param>
/// <param name="pageState">A dictionary of state preserved by this page during an earlier
/// session. This will be null the first time a page is visited.</param>
protected override async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
{
// Allow saved page state to override the initial item to display
if (pageState != null && pageState.ContainsKey("SelectedItem"))
{
navigationParameter = pageState["SelectedItem"];
}
Geolocator locator = new Geolocator();
Geoposition geoPos = await locator.GetGeopositionAsync();
Geocoordinate geoCoord = geoPos.Coordinate;
String YWSID = "Bi9Fsbfon92vmD4DkkO4Fg";
String url;
if (navigationParameter != "")
{
url = "http://api.yelp.com/business_review_search?term=food&location=" + navigationParameter + "&ywsid=" + YWSID;
}
else
{
url = "http://api.yelp.com/business_review_search?term=food&lat=" + geoCoord.Latitude + "&long=" + geoCoord.Longitude + "&ywsid=" + YWSID;
}
var httpClient = new HttpClient();
String content = await httpClient.GetStringAsync(url);
response = JsonObject.Parse(content);
this.Frame.Navigate(typeof(MainPage),response);
}
示例13: Parse
public static TwitterHashTagEntitity Parse(JsonObject entity) {
return new TwitterHashTagEntitity {
Text = entity.GetString("text"),
StartIndex = entity.GetArray("indices").GetInt(0),
EndIndex = entity.GetArray("indices").GetInt(1)
};
}
示例14: PostJSON
public void PostJSON( string inURL, JsonObject inJSON, Action< string, JsonObject > inCallback )
{
var headers = new Dictionary< string, string >();
headers[ "Content-Type" ] = "application/json";
var jsonString = SimpleJson.SimpleJson.SerializeObject( inJSON );
Post( inURL, System.Text.Encoding.UTF8.GetBytes( jsonString ), headers, ( string inError, WWW inWWW ) =>
{
if( inCallback != null )
{
JsonObject obj = null;
if ( string.IsNullOrEmpty( inError ) && ! string.IsNullOrEmpty( inWWW.text ) )
{
Debug.Log("Response: " + inWWW.text );
object parsedObj = null;
if ( SimpleJson.SimpleJson.TryDeserializeObject( inWWW.text, out parsedObj ) )
{
obj = ( JsonObject ) parsedObj;
}
}
inCallback( inError, obj );
}
} );
}
示例15: JsonObjectConstructorParmsTest
public void JsonObjectConstructorParmsTest()
{
JsonObject target = new JsonObject();
Assert.Equal(0, target.Count);
string key1 = AnyInstance.AnyString;
string key2 = AnyInstance.AnyString2;
JsonValue value1 = AnyInstance.AnyJsonValue1;
JsonValue value2 = AnyInstance.AnyJsonValue2;
List<KeyValuePair<string, JsonValue>> items = new List<KeyValuePair<string, JsonValue>>()
{
new KeyValuePair<string, JsonValue>(key1, value1),
new KeyValuePair<string, JsonValue>(key2, value2),
};
target = new JsonObject(items[0], items[1]);
Assert.Equal(2, target.Count);
ValidateJsonObjectItems(target, key1, value1, key2, value2);
target = new JsonObject(items.ToArray());
Assert.Equal(2, target.Count);
ValidateJsonObjectItems(target, key1, value1, key2, value2);
// Invalid tests
items.Add(new KeyValuePair<string, JsonValue>(key1, AnyInstance.DefaultJsonValue));
ExceptionHelper.Throws<ArgumentException>(delegate { new JsonObject(items[0], items[1], items[2]); });
ExceptionHelper.Throws<ArgumentException>(delegate { new JsonObject(items.ToArray()); });
}