本文整理汇总了C#中System.Json.JsonObject.asString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonObject.asString方法的具体用法?C# JsonObject.asString怎么用?C# JsonObject.asString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.asString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
public Section Build(JsonObject section, JsonValue data)
{
var sec = new Section(section.asString("caption"), section.asString("footer"));
if (!string.IsNullOrEmpty(section.asString("captionImage"))) {
var imgDevice = section.asString("captionImage").Split(' ');
var img = UIDevice.CurrentDevice.UserInterfaceIdiom==UIUserInterfaceIdiom.Phone ? imgDevice[0] : imgDevice[1];
sec.HeaderView = new UIImageView(UIImage.FromBundle(img));
}
if (section.ContainsKey("elements")){
foreach (JsonObject elem in section["elements"]) {
var dataForElement = data;
var bindExpression = elem.asString("bind");
if (bindExpression!=null) {
try {
if (data!=null && data.JsonType==JsonType.Object){
var bind = elem.asString("bind");
if (data != null && !string.IsNullOrEmpty(bind) && data.ContainsKey(bind)) {
dataForElement = data[bind];
}
} else if (bindExpression.StartsWith("#")) {
dataForElement = _controller.GetValue(bindExpression.Replace("#", ""));
}
} catch (Exception e){
Console.WriteLine("Exception when binding element " + elem.ToString()+ " - " + e.ToString());
}
}
_parseElement(elem, sec, dataForElement);
}
} else if (section.ContainsKey("iterate") && data != null){
string iterationname = section["iterate"];
JsonArray iterationdata = null;
if (iterationname.Contains("#")){ // for when list is in member of object
var splittedName = iterationname.Split('#');
var obj = (JsonObject)data[splittedName[0]];
iterationdata = (JsonArray)obj[splittedName[1]];
} else {
iterationdata = string.IsNullOrEmpty(iterationname) ? (JsonArray)data : (JsonArray)data[iterationname];
}
string emptyMessage = section.ContainsKey("empty") ? section["empty"].CleanString() : "Empty";
var template = (JsonObject)section["template"];
var items = iterationdata.ToList();
if (items.Count>0) {
foreach(JsonValue v in items){
_parseElement(template, sec, v);
}
} else {
sec.Add(new EmptyListElement(emptyMessage));
}
} else if (section.ContainsKey("iterateproperties") && data != null){
string iterationname = section["iterateproperties"];
string emptyMessage = section.ContainsKey("empty") ? section["empty"].CleanString() : "Empty";
var iterationdata = string.IsNullOrEmpty(iterationname) ? (JsonObject)data
: data.ContainsKey(iterationname) ? (JsonObject)data[iterationname] : null;
var template = (JsonObject)section["template"];
var items = iterationdata == null ? new List<string>() : iterationdata.Keys;
if (items.Count>0) {
foreach(string v in items){
var obj = new JsonObject();
obj.Add(v, iterationdata[v]);
_parseElement(template, sec, obj);
}
} else {
sec.Add(new EmptyListElement(emptyMessage));
}
}
return sec;
}
示例2: _createButtonItemFor
private UIBarButtonItem _createButtonItemFor(string property, JsonValue json, JsonObject valuesJson){
var item = (JsonObject)json[property];
string datavalue = null, id = null;
id = item.asString(Constants.Id);
Activity action = null;
UIBarButtonItem button;
if (valuesJson!=null && !string.IsNullOrEmpty(id)){
datavalue = valuesJson.asString(id);
}
if (item.ContainsKey(Constants.Action)) {
action = new ControllerAction(datavalue ?? item.asString(Constants.Action));
} else if (item.ContainsKey(Constants.Activity)) {
action = ActivityFactory.Create(item.asString(Constants.Activity));
}
if (action==null)
return null;
if (item.ContainsKey(Constants.Image)){
button = new UIBarButtonItem(UIImage.FromBundle(item.asString(Constants.Image)), UIBarButtonItemStyle.Plain, (object o, EventArgs a)=>{
action.Execute(this, null, null);
});
} else {
button = new UIBarButtonItem(item.asString(Constants.Caption), UIBarButtonItemStyle.Plain, (object o, EventArgs a)=>{
action.Execute(this, null, null);
});
}
return button;
}
示例3: _parseElement
private void _parseElement(JsonObject json, Section section, JsonValue data){
string type = "Unknown";
try {
type = json["type"];
if (type=="HiddenElement"){
var name = json.asString("id");
_controller.SetValue(name, data==null? json.asString("value") : data.CleanString());
} else {
string id = (json.ContainsKey("id") ? json["id"] : null);
var newElement = ElementParsers.Parsers[type](json, _controller, data);
if (newElement!=null) {
if (!string.IsNullOrEmpty(id))
newElement.ID = new NSString(id);
section.Add(newElement);
}
}
} catch (Exception e){
Console.WriteLine("Problem parsing element. Element was skipped. Type: "+type+" = " + e.ToString());
}
}