小编Amr*_*afy的帖子

在不使用变量名的情况下打印嵌套的JSON

Web服务返回以下嵌套的json对象:

{"age":"21-24","gender":"Male","location":"San Francisco, CA","influencer score":"70-79","interests":{"Entertainment":{"Celebrities":{"Megan Fox":{},"Michael Jackson":{}},},"Social Networks & Online Communities":{"Web Personalization": {},"Journals & Personal Sites": {},},"Sports":{"Basketball":{}},},"education":"Completed Graduate School","occupation":"Professional/Technical","children":"No","household_income":"75k-100k","marital_status":"Single","home_owner_status":"Rent"}
Run Code Online (Sandbox Code Playgroud)

我只是想在不指定属性名称的情况下遍历此对象,我尝试了以下代码:

for (var data in json_data) {
    alert("Key:" + data + " Values:" + json_data[data]);
}
Run Code Online (Sandbox Code Playgroud)

但是如果它是一个嵌套值,它会将值打印为[object Object],是否有任何方法可以更深入地迭代嵌套值?

javascript json

5
推荐指数
1
解决办法
5440
查看次数

PHP base64_decode C#等价

我正在尝试模仿执行以下操作的PHP脚本:

  1. 用+符号替换GET变量的每个空格($ var = preg_replace("/\s /","+",$ _ GET ['var']);)
  2. 解码为base64:base64_decode($ var);

我添加了一个方法执行base64解码:

        public string base64Decode(string data)
    {
        try
        {
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();

            System.Text.Decoder utf8Decode = encoder.GetDecoder();

            byte[] todecode_byte = Convert.FromBase64String(data);
            int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char);
            return result;
        }
        catch (Exception e)
        {
            throw new Exception("Error in base64Decode" + e.Message);
        }
    }
Run Code Online (Sandbox Code Playgroud)

但它接缝说UTF-8没有完成这项工作,所以我尝试了相同的方法,但使用的是UTF-7

        public string base64Decode(string data)
    {
        try
        {
            System.Text.UTF7Encoding encoder = …
Run Code Online (Sandbox Code Playgroud)

php c# base64

2
推荐指数
1
解决办法
5842
查看次数

标签 统计

base64 ×1

c# ×1

javascript ×1

json ×1

php ×1