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],是否有任何方法可以更深入地迭代嵌套值?
我正在尝试模仿执行以下操作的PHP脚本:
我添加了一个方法执行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)