ToJSON() public méthode

public ToJSON ( int prefix ) : string
prefix int
Résultat string
Exemple #1
0
        public void Save()
        {
            var path = GetFilePath();

            if (Application.isEditor && !Application.isPlaying)
            {
                var simvaconf = new SimpleJSON.JSONClass();
                simvaconf["study"]         = Study;
                simvaconf["host"]          = Host;
                simvaconf["protocol"]      = Protocol;
                simvaconf["port"]          = Port;
                simvaconf["sso"]           = SSO;
                simvaconf["client_id"]     = ClientId;
                simvaconf["url"]           = URL;
                simvaconf["trace_storage"] = TraceStorage.ToString();
                simvaconf["backup"]        = Backup.ToString();
                simvaconf["realtime"]      = Realtime.ToString();
                System.IO.File.WriteAllText(path, simvaconf.ToJSON(4));
            }
        }
        /*
         * {
                "type": "group_info", //标记
                "group": //group 信息
                 {
                    "member":
                    [//成员
                        {
                            "uid": ""//用户id
                        },
                        ...
                    ],
                    "vid": "", //场馆id
                    "name": "",//..名字
                    "address": "",//..地址
                    "time": "",//..时间
                    "latitude": "",//..经度
                    "longtitude": "",//..纬度
                    "state": "",//..状态 3种状态 0 是未预订 2是预订 1是投票状态
                    "max": ""//..最大成员数 默认10
                }
            }
         */
        public string GetExtJson(string groupID)
        {
            Monitor.Enter(userGroupDict);
            try
            {
                SportMatchGroup group = groupList.Find(a => { return a.groupID == groupID; });
                Venue venue = group.venue;

                JSONClass jc = new JSONClass();
                jc.Add("type", new JSONData("group_info"));
                JSONClass jc_1 = new JSONClass();
                JSONArray ja_1_1 = new JSONArray();
                var itr = userGroupDict.GetEnumerator();
                while (itr.MoveNext())
                {
                    string groupid = itr.Current.Value;
                    if (groupid != groupID)
                        continue;
                    string uuid = itr.Current.Key;
                    JSONClass jc_1_1_i = new JSONClass();
                    jc_1_1_i.Add("uid", new JSONData(uuid));
                    ja_1_1.Add(jc_1_1_i);
                }
                jc_1.Add("member", ja_1_1);
                if (venue == null)
                {
                    jc_1.Add("vid", new JSONData(""));
                    jc_1.Add("name", new JSONData(""));
                    jc_1.Add("address", new JSONData(""));
                    jc_1.Add("time", new JSONData(""));
                    jc_1.Add("latitude", new JSONData(""));
                    jc_1.Add("longtitude", new JSONData(""));
                    jc_1.Add("state", new JSONData(0));
                }
                else
                {
                    jc_1.Add("vid", new JSONData(venue.id));
                    jc_1.Add("name", new JSONData(venue.name));
                    jc_1.Add("address", new JSONData(venue.address));
                    jc_1.Add("time", new JSONData(venue.time));
                    jc_1.Add("latitude", new JSONData(venue.latitude));
                    jc_1.Add("longtitude", new JSONData(venue.longitude));
                    jc_1.Add("state", new JSONData(2));
                }
                jc_1.Add("max", new JSONData(10));
                jc.Add("group", jc_1);
                return jc.ToJSON(0);
            }
            finally
            {
                Monitor.Exit(userGroupDict);
            }
        }
Exemple #3
0
 public string SendUserInvite(string from, string to,string fromUID,string fromNickname)
 {
     JSONClass jc = new JSONClass();
     jc.Add("form", fromUID);
     return SendMsgToUser(from, to, fromNickname + " 邀请你加入新活动!", jc.ToJSON(0));
 }
Exemple #4
0
        /*
         *{
                "target_type":"users",     // users 给用户发消息。chatgroups 给群发消息,chatrooms 给聊天室发消息
                "target":["testb","testc"], // 注意这里需要用数组,数组长度建议不大于20,即使只有
                                            // 一个用户u1或者群组,也要用数组形式 ['u1'],给用户发
                                            // 送时数组元素是用户名,给群组发送时数组元素是groupid
                "msg":{  //消息内容
                    "type":"txt",  // 消息类型,不局限与文本消息。任何消息类型都可以加扩展消息
                    "msg":"消息"    // 随意传入都可以
                },
                "from":"testa",  //表示消息发送者。无此字段Server会默认设置为"from":"admin",有from字段但值为空串("")时请求失败
                "ext":{   //扩展属性,由APP自己定义。可以没有这个字段,但是如果有,值不能是"ext:null"这种形式,否则出错
                    "attr1":"v1"   // 消息的扩展内容,可以增加字段,扩展消息主要解析不分。
                }
            }
         */
        public string SendMessage(string targetType, string[] targetID, string msgType, string msgText, string fromUUID, string extJson = null)
        {
            JSONClass jc = new JSONClass();
            jc.Add("target_type", JD(targetType));
            JSONArray ja = new JSONArray();
            foreach (string tID in targetID)
            {
                ja.Add(JD(tID));
            }
            jc.Add("target", ja);
            JSONClass jmsg = new JSONClass();
            jmsg.Add("type", JD(msgType));
            jmsg.Add("msg", JD(msgText));
            jc.Add("msg", jmsg);
            if (fromUUID != null)
                jc.Add("from", fromUUID);
            if (extJson != null)
                jc.Add("ext", JSON.Parse(extJson));

            string postData = jc.ToJSON(0);
            string result = ReqUrl(easeMobUrl + "messages", "POST", postData, token);
            return result;
        }