本文整理汇总了C#中JsonArray类的典型用法代码示例。如果您正苦于以下问题:C# JsonArray类的具体用法?C# JsonArray怎么用?C# JsonArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JsonArray类属于命名空间,在下文中一共展示了JsonArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAll
public JsonValue GetAll()
{
JsonObject parameters = WebOperationContext.Current.IncomingRequest.GetQueryStringAsJsonObject();
JsonValue term;
string termValue = parameters.TryGetValue("term", out term) ? term.ReadAs<string>() : String.Empty;
using (SqlConnection sc = new SqlConnection(connectionString))
{
sc.Open();
using (SqlCommand getAll = new SqlCommand("SELECT Email FROM Contact WHERE (Email LIKE @term)", sc))
{
getAll.Parameters.AddWithValue("@term", termValue + "%");
SqlDataReader reader = getAll.ExecuteReader();
JsonArray results = new JsonArray();
while (reader.Read())
{
results.Add(Convert.ToString(reader[0], CultureInfo.InvariantCulture));
}
return results;
}
}
}
示例2: PostToWall
public void PostToWall()
{
try
{
var actionLinks = new JsonArray();
var learnMore = new JsonObject();
learnMore.Add("text", "Learn more about Big Profile");
learnMore.Add("href", "http://myapp.no/BigProfile");
var appStore = new JsonObject();
appStore.Add("text", "Visit App Store");
appStore.Add("href", "http://myapp.no/BigProfileAppStore");
//actionLinks.Add(learnMore);
actionLinks.Add(appStore);
var attachment = new JsonObject();
attachment.Add("name", "Big Profile");
attachment.Add("description", "Make your profile stand out with a big profile picture stretched across the new Facebook design. Available in App Store!");
attachment.Add("href", "http://myapp.no/BigProfile");
var parameters = new NSMutableDictionary();
parameters.Add(new NSString("user_message_prompt"), new NSString("Tell your friends"));
parameters.Add(new NSString("attachment"), new NSString(attachment.ToString()));
parameters.Add(new NSString("action_links"), new NSString(actionLinks.ToString()));
_facebook.Dialog("stream.publish", parameters, facebookDialogDelegate);
}
catch(Exception ex)
{
Console.WriteLine("Exception when showing dialog: {0}", ex);
}
}
示例3: Main
static void Main(string[] args)
{
//var json = new JsonArray(
// new JsonObject(
// new JsonMember("A", new JsonNumber(1)),
// new JsonMember("B", new JsonNumber(2)),
// new JsonMember("C", new JsonArray(new JsonNumber(1), new JsonNumber(2)))),
// new JsonObject(
// new JsonMember("D", new JsonNumber(3)),
// new JsonMember("E", new JsonNumber(4))));
var nested = new JsonObject(
new JsonMember("A", new JsonNumber(3)),
new JsonMember("A", new JsonNumber(3.01m)),
new JsonMember("A", new JsonNumber(3)));
var array = new JsonArray(nested, nested, nested);
var array2 = new JsonArray(new JsonNumber(3), new JsonNumber(2), new JsonNumber(1));
JsonValue json = new JsonObject(
new JsonMember("A", new JsonString("\u0460\u849c\u8089")),
new JsonMember("B", new JsonNumber(2)),
new JsonMember("C",
new JsonObject(
new JsonMember("A", new JsonNumber(3)),
new JsonMember("A", new JsonNumber(3)),
new JsonMember("A", new JsonNumber(3)),
new JsonMember("ComplexArray", array),
new JsonMember("SimpleArray", array2))));
Console.WriteLine(json.Stringify(true));
json = Json.CreateAst(json.Stringify(true));
Console.WriteLine(json.Stringify(true));
}
示例4: CreateFromScratch
private static void CreateFromScratch()
{
rootObject = new JsonObject();
readList = new JsonArray();
rootObject.Add(ReadListKey, readList);
}
示例5: CompareJsonArrayTypes
private static bool CompareJsonArrayTypes(JsonArray objA, JsonArray objB)
{
bool retValue = true;
if (objA == null || objB == null || objA.Count != objB.Count || objA.IsReadOnly != objB.IsReadOnly)
{
return false;
}
try
{
for (int i = 0; i < objA.Count; i++)
{
if (!Compare(objA[i], objB[i]))
{
Log.Info("JsonValueVerifier (JsonArrayType) Error: objA[{0}] = {1}", i, objA[i].ToString());
Log.Info("JsonValueVerifier (JsonArrayType) Error: objB[{0}] = {1}", i, objB[i].ToString());
return false;
}
}
}
catch (Exception e)
{
Log.Info("JsonValueVerifier (JsonArrayType) Error: An Exception was thrown: " + e);
return false;
}
return retValue;
}
示例6: JsonArrayBindingSource
/// <summary>
/// Initializes a new instance of <see cref="JsonArrayBindingSource"/> with a source <see cref="JsonArray"/> and the type of <see cref="JsonValue"/> that is contained in the array.
/// </summary>
/// <param name="sourceArray">The source array containing values.</param>
/// <param name="valueType">The type of <see cref="JsonValue"/> the <see cref="JsonArray"/> contains.</param>
/// <remarks>
/// If the source <see cref="JsonArray"/> is empty, use the constructor with the constructor <see cref="JsonArrayBindingSource.JsonArrayBindingSource(JsonArray, Type, IEnumerable{JsonObject.JsonObjectPropertyDescriptor})"/> to define the properties that should be available.
/// </remarks>
public JsonArrayBindingSource(JsonArray sourceArray, Type valueType)
{
_array = sourceArray;
vtype = valueType;
if (sourceArray.Count > 0)
ReadProperties();
else
{
if (valueType == typeof(JsonString) || valueType == typeof(JsonNumber) || valueType == typeof(JsonBoolean))
{
PropertyDescriptorCollection c = TypeDescriptor.GetProperties(valueType);
PropertyDescriptor[] ca = new PropertyDescriptor[1];
foreach (PropertyDescriptor item in c)
{
if (item.Name == "Value")
{
ca[0] = item;
props = new PropertyDescriptorCollection(ca);
break;
}
}
}
else
props = TypeDescriptor.GetProperties(valueType);
}
}
示例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: SerializeArray
/// <summary>
/// 序列化JSONArray对象
/// </summary>
/// <param name="jsonArray"></param>
/// <returns></returns>
public static string SerializeArray(JsonArray jsonArray)
{
StringBuilder sb = new StringBuilder();
sb.Append("[");
for (int i = 0; i < jsonArray.Count; i++)
{
if (jsonArray[i] is JsonObject)
{
sb.Append(string.Format("{0},", SerializeObject((JsonObject)jsonArray[i])));
}
else if (jsonArray[i] is JsonArray)
{
sb.Append(string.Format("{0},", SerializeArray((JsonArray)jsonArray[i])));
}
else if (jsonArray[i] is String)
{
sb.Append(string.Format("\"{0}\",", jsonArray[i]));
}
else
{
sb.Append(string.Format("\"{0}\",", ""));
}
}
if (sb.Length > 1)
sb.Remove(sb.Length - 1, 1);
sb.Append("]");
return sb.ToString();
}
示例9: 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());
}
示例10: Stringify
public string Stringify()
{
JsonArray jsonArray = new JsonArray();
foreach (School school in Education)
{
jsonArray.Add(school.ToJsonObject());
}
JsonObject jsonObject = new JsonObject();
jsonObject[idKey] = JsonValue.CreateStringValue(Id);
// Treating a blank string as null
if (String.IsNullOrEmpty(Phone))
{
jsonObject[phoneKey] = JsonValue.CreateNullValue();
}
else
{
jsonObject[phoneKey] = JsonValue.CreateStringValue(Phone);
}
jsonObject[nameKey] = JsonValue.CreateStringValue(Name);
jsonObject[educationKey] = jsonArray;
jsonObject[timezoneKey] = JsonValue.CreateNumberValue(Timezone);
jsonObject[verifiedKey] = JsonValue.CreateBooleanValue(Verified);
return jsonObject.Stringify();
}
示例11: 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());
}
示例12: 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;
}
示例13: Start
// Use this for initialization
void Start ()
{
// json对象构造示例
JsonObject root = new JsonObject();
root["age"] = 25;
root["name"] = "rare";
JsonObject obj = new JsonObject();
root["person"] = obj;
obj["age"] = 1;
obj["name"] = "even";
JsonArray arr = new JsonArray();
arr[0] = "ComputerGrphic";
arr[1] = "Unity3D";
arr[2] = "Graphic";
root["books"] = arr;
// json取值
int a = root["age"];
Debug.Log("age:"+a.ToString());
string v = root["name"];
Debug.Log("name:" + v);
// save json and format
string strSerializeFile = Application.dataPath + "json/home.json";
RareJson.Serialize(root, strSerializeFile, true);
// json解析
string strJsonName = Application.dataPath + "json/Contents.json";
JsonNode node = RareJson.ParseJsonFile(strJsonName);
// json not format
strSerializeFile = Application.dataPath + "json/serialize.json";
RareJson.Serialize(node, strSerializeFile, false);
}
示例14: Visit
/// <summary>
/// Visits a json array.
/// </summary>
/// <param name="jsonArray">The json array being visited.</param>
public void Visit(JsonArray jsonArray)
{
ExceptionUtilities.CheckArgumentNotNull(jsonArray, "jsonArray");
this.writer.StartArrayScope();
jsonArray.Elements.ForEach(e => e.Accept(this));
this.writer.EndScope();
}
示例15: Parse
public static TwitterCoordinates Parse(JsonArray array) {
if (array == null) return null;
return new TwitterCoordinates {
Latitude = array.GetDouble(1),
Longitude = array.GetDouble(0)
};
}