本文整理汇总了C#中JSONArray类的典型用法代码示例。如果您正苦于以下问题:C# JSONArray类的具体用法?C# JSONArray怎么用?C# JSONArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JSONArray类属于命名空间,在下文中一共展示了JSONArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public override void Init(object[] data) {
base.Init(data);
List<Buddy> buddyList = SmartfoxClient.Instance.GetBuddyList();
if (buddyList.Count > 0) {
Utils.SetActive(noFriendLabel, false);
EventDelegate.Set(btnSendInvite.onClick, EventSendInvite);
JSONObject friend;
friendList = new JSONArray();
for (int i = 0; i < buddyList.Count; i++) {
friend = new JSONObject();
if (buddyList[i].IsOnline) {
friend.Add("displayName", buddyList[i].GetVariable("displayName").GetStringValue());
friend.Add("cash", (long)buddyList[i].GetVariable("cash").GetDoubleValue());
friend.Add("username", buddyList[i].Name);
friendList.Add(friend);
}
}
InitScrollViewData(friendList);
} else {
// TO DO - dont have friend message
Utils.SetActive(scrollview.gameObject, false);
Utils.SetActive(btnSendInvite.gameObject, false);
Utils.SetActive(noFriendLabel, true);
Debug.Log("----------- DONE HAVE ANY FRIEND ----------------");
}
}
示例2: LoadFriendRank
public void LoadFriendRank(Action callback)
{
JSONArray friendList = new JSONArray ();
foreach(JSONValue item in UserSingleton.Instance.FriendList){
JSONObject friend = item.Obj;
friendList.Add (friend ["id"]);
}
JSONObject requestBody = new JSONObject ();
requestBody.Add ("UserID", UserSingleton.Instance.UserID);
requestBody.Add ("FriendList", friendList);
HTTPClient.Instance.POST (Singleton.Instance.HOST + "/Rank/Friend", requestBody.ToString(), delegate(WWW www) {
Debug.Log("LoadFriendRank" + www.text);
string response = www.text;
JSONObject obj = JSONObject.Parse(response);
JSONArray arr = obj["Data"].Array;
foreach(JSONValue item in arr){
int rank = (int)item.Obj["Rank"].Number;
if(FriendRank.ContainsKey(rank)){
FriendRank.Remove(rank);
}
FriendRank.Add(rank,item.Obj);
}
callback();
});
}
示例3: ShouldLoadData
private bool ShouldLoadData(Tab selectedTab) {
JSONArray checkData = new JSONArray();
DateTime? checkTime = null;
switch(selectedTab) {
case Tab.TOP_RICHER:
checkData = topRicherList;
checkTime = topRicherLoadTime;
break;
case Tab.TOP_WINNER:
checkData = topWinnerList;
checkTime = topWinnerLoadTime;
break;
default:
return false;
}
if (checkData == null || checkData.Length == 0) {
return true;
} else {
if (checkTime.HasValue) {
if (Utils.CurrentTime().Subtract((DateTime)checkTime).TotalSeconds >= RELOAD_DATA_SECONDS) {
return true;
} else {
return false;
}
} else {
return true;
}
}
}
示例4: Init
public override void Init(object[] data) {
base.Init(data);
EventDelegate.Set(tabInvite.onClick, EventTabInvite);
EventDelegate.Set(tabFriends.onClick, EventTabFriends);
// Get list friends from smartfox buddy list
List<Buddy> buddyList = SmartfoxClient.Instance.GetBuddyList();
if (buddyList.Count > 0) {
JSONObject friend;
friendList = new JSONArray();
for (int i = 0; i < buddyList.Count; i++) {
friend = new JSONObject();
if (buddyList[i].IsOnline) {
friend.Add("displayName", buddyList[i].GetVariable("displayName").GetStringValue());
friend.Add("cash", (long)buddyList[i].GetVariable("cash").GetDoubleValue());
friend.Add("avatar", buddyList[i].GetVariable("avatar").GetStringValue());
friend.Add("facebookId", buddyList[i].GetVariable("facebookId").GetStringValue());
} else {
friend.Add("displayName", buddyList[i].GetVariable("$displayName").GetStringValue());
friend.Add("cash", (long)buddyList[i].GetVariable("$cash").GetDoubleValue());
friend.Add("avatar", buddyList[i].ContainsVariable("$avatar") ? buddyList[i].GetVariable("$avatar").GetStringValue() : string.Empty);
friend.Add("facebookId", buddyList[i].ContainsVariable("$facebookId") ? buddyList[i].GetVariable("$facebookId").GetStringValue() : string.Empty);
}
friend.Add("username", buddyList[i].Name);
friendList.Add(friend);
}
InitScrollViewData(friendList);
} else {
Utils.SetActive(scrollview.gameObject, false);
Debug.Log("----------- DONE HAVE ANY FRIEND ----------------");
}
}
示例5: decodeArray
public JSONArray decodeArray(string str, ref int index)
{
if (str[index] != '[') return null;
index++;
JSONArray array = new JSONArray();
bool array_should_over = false;
while (index < str.Length)
{
index = passWhiteSpace(str, index);
if (str[index] == ']')
{
index++;
return array;
}
else if (array_should_over)
{
throw new JSONError(str, index);
}
array.addJSONValue(decodeValue(str, ref index));
index = passWhiteSpace(str, index);
if (str[index] != ',')
{
array_should_over = true;
}
else
{
index++;
}
}
return null;
}
示例6: ToJSON
//JSON Format:
/*
{
"session": {
"id": "session1234",
"player": "user123",
"game": "game1",
"version": "version 1.0"
},
"play_events" :
[
{ "time": "2015-02-17T22:43:45-5:00", "event": "PowerUp.FireBall", "value": "1.0", "level": "1-1"},
{ "time": "2015-02-17T22:45:45-5:00", "event": "PowerUp.Mushroom", "value": "2.0", "level": "1-1"}
]
}
*/
public static string ToJSON(Gloggr_Report r)
{
JSONNode n = new JSONClass();
n.Add ("session", Gloggr_SessionHeader.ToJSONObject(r.session) );
JSONArray a = new JSONArray();
foreach(Gloggr_PlayEvent e in r.play_events)
{
a.Add(Gloggr_PlayEvent.ToJSONObject(e));
}
n.Add ("play_events", a);
return n.ToString();
// string json = JsonConvert.SerializeObject(e, Formatting.Indented);
// //from Gloggr_SessionHeader.ToJSON
// //json = Gloggr_SessionHeader.FormatJSONKeys(json);
// //from Gloggr_PlayEvent.ToJSON
// //json = Gloggr_PlayEvent.FormatJSONKeys(json);
// return json;
}
示例7: SerializeArray
public static string SerializeArray(JSONArray jsonArray)
{
StringBuilder builder = new StringBuilder();
builder.Append("[");
for (int i = 0; i < jsonArray.Count; i++)
{
if (jsonArray[i] is JSONObject)
{
builder.Append(string.Format("{0},", SerializeObject((JSONObject) jsonArray[i])));
}
else if (jsonArray[i] is JSONArray)
{
builder.Append(string.Format("{0},", SerializeArray((JSONArray) jsonArray[i])));
}
else if (jsonArray[i] is string)
{
builder.Append(string.Format("{0},", jsonArray[i]));
}
else
{
builder.Append(string.Format("{0},", jsonArray[i]));
}
}
if (builder.Length > 1)
{
builder.Remove(builder.Length - 1, 1);
}
builder.Append("]");
return builder.ToString();
}
示例8: JSONValue
/// <summary>
/// Construct a copy of the JSONValue given as a parameter
/// </summary>
/// <param name="value"></param>
public JSONValue(JSONValue value)
{
Type = value.Type;
switch (Type)
{
case JSONValueType.String:
Str = value.Str;
break;
case JSONValueType.Boolean:
Boolean = value.Boolean;
break;
case JSONValueType.Number:
Number = value.Number;
break;
case JSONValueType.Object:
if (value.Obj != null)
Obj = new JSONObject(value.Obj);
break;
case JSONValueType.Array:
Array = new JSONArray(value.Array);
break;
}
}
示例9: Init
public override void Init(object[] data) {
gameType = (BaseGameScreen.GameType)data[0];
EventDelegate.Set(btnBack.onClick, BackToSelectGame);
EventDelegate.Set(btnCreateRoom.onClick, OpenPopupCreateRoom);
// fake room list
// roomList = new JSONArray();
roomList = ((JSONObject)data[1]).GetArray("rooms");
Debug.Log(roomList.ToString());
// fake room min bet
// int[] roomBet = new int[] { 10000, 100000, 520000, 2000000};
// for (int i = 0; i < roomList.Length; i++) {
// JSONObject room = roomList[i].Obj;
// room.Add("id", i);
// room.Add("name", "room " + i);
// room.Add("minBet", roomBet[i % 4]);
// // roomList.Add(room);
// }
InitScrollViewData();
// Set Bet Filter
for (int i = 0; i < betFilterList.Length; i++) {
betFilterPopupList.items.Add(betFilterList[i]);
}
EventDelegate.Set(betFilterPopupList.onChange, EventFilterBet);
crtBetFilter = betFilterList[0];
}
示例10: Start
// Use this for initialization
void Start()
{
Debug.Log ("Loading credits file");
creditsAsset = Resources.Load ("Credits") as TextAsset;
creditsJson = JSON.Parse (creditsAsset.text) as JSONArray;
Invoke ("ShowCredits", 2f);
}
示例11: ExportData
public static JSONArray ExportData(this List<int> list)
{
var json_array = new JSONArray();
foreach (var num in list)
json_array.Add(num);
return json_array;
}
示例12: ToJSON
public JSONValue ToJSON()
{
var result = new JSONArray();
foreach (var item in this.Items)
{
result.AddValue(item.ToObject());
}
return result;
}
示例13: setChatterArray
public void setChatterArray(JSONArray records)
{
chatterArray = records;
chatterFetched = true;
if (records.Length > 0) {
enableChatter();
}
}
示例14: ProcessSwungMens
/// <summary> Synchronise les SwungMens acheté et achetable </summary>
private static void ProcessSwungMens(JSONArray array)
{
Settings.Instance.ResetDefaultPlayer ();
foreach (JSONValue value in array)
{
Player p = new Player (value.Obj);
Settings.Instance.AddOrUpdate_Player (p);
if (!Settings.Instance.Default_player.ContainsKey (p.UID))
Settings.Instance.Default_player.Add (p.UID, p);
}
}
示例15: create
public static Property_int create(JSONArray template)
{
switch (template.getString(0))
{
case "mul": return new Property_Mul(template);
case "add": return new Property_Add(template);
case "count": return new Property_Count(template.getArray(1));
case "amountOf": return new Property_AmountOf(ResourceType.get(template.getString(1)));
default: throw new ArgumentException("Invalid property " + template.getString(0));
}
}