JSONObject.ToDictionary C# (CSharp) Method

ToDictionary() public method

public ToDictionary ( ) : string>.Dictionary
return string>.Dictionary
	public Dictionary<string, string> ToDictionary()
	{
		if (type == Type.OBJECT)
		{
			Dictionary<string, string> result = new Dictionary<string, string>();
			for (int i = 0; i < list.Count; i++)
			{
				JSONObject val = list[i];
				switch (val.type)
				{
					case Type.STRING: result.Add(keys[i], val.str); break;
					case Type.NUMBER: result.Add(keys[i], val.n + ""); break;
					case Type.BOOL: result.Add(keys[i], val.b + ""); break;
					default: Debug.LogWarning("Omitting object: " + keys[i] + " in dictionary conversion"); break;
				}
			}
			return result;
		}
		Debug.LogWarning("Tried to turn non-Object JSONObject into a dictionary");
		return null;
	}
	public static implicit operator bool (JSONObject o)

Usage Example

Example #1
0
    /// <summary>
    /// 获取授权用户信息
    /// </summary>
    /// <param name="token"></param>
    /// <param name="openId"></param>
    private void GetAuthUserInfoJosnMap(string token, string openId)
    {
        //获取用户个人信息(UnionID机制)
        string userinfourl = "https://api.weixin.qq.com/sns/userinfo?access_token=" +
                             token + "&openid=" + openId;

        UnityWebRequest wxuserinfoReq = UnityWebRequest.Get(userinfourl);

        wxuserinfoReq.SetRequestHeader("Content-Type", "application/json");
        wxuserinfoReq.Send();
        while (!wxuserinfoReq.isDone)
        {
        }
        string userInfoContent = wxuserinfoReq.downloadHandler.text.Trim();

        wxuserinfoReq.Dispose();

        var userInfojsonobj = new JSONObject(userInfoContent);

        AuthUserInfoMap.Clear();
        AuthUserInfoMap = userInfojsonobj.ToDictionary();

        //删除headimgurl中多余的反斜杠(\)
        string headurlstr;

        if (AuthUserInfoMap.TryGetValue("headimgurl", out headurlstr))
        {
            string headimgurl = headurlstr.Replace("\\", "");
            AuthUserInfoMap["headimgurl"] = headimgurl;
        }
    }
All Usage Examples Of JSONObject::ToDictionary