我以JSONArray格式从服务器获得响应。我无法检索数组的内容,我的JSONArray也没有方括号。
我在php中将响应作为json_encode($array)
传递给服务器端
response {
community = “worker”
communitystr = "<null>";
workspace = abs;
email = "<null>";
admin = false;
persona = "<null>";
userinfo = {
info = {
contact1 = {
firstname = “jon”;
lastname = “Doe”
phone = “9885678905”;
objectname = contact;
id = 9;
};
event1 = {
eventname = “party”;
description = "";
order = 6;
id = 4;
objectname = events;
};
files = {
filename = “sample”;
description = "";
order = 11;
id = 11;
objectname = files;
};
};
};
};
我检查了很多链接,并且都使用了JSONObject()
。但同样对我不起作用。
如何获取此JSON响应中的每个值?
答案 0 :(得分:1)
你必须使用
:而不是=
而不是;
...
请注意以下格式:
{
"Herausgeber": "Xema",
"Nummer": "1234-5678-9012-3456",
"Deckung": 2e+6,
"Waehrung": "EURO",
"Inhaber":
{
"Name": "Mustermann",
"Vorname": "Max",
"maennlich": true,
"Hobbys": [ "Reiten", "Golfen", "Lesen" ],
"Alter": 42,
"Kinder": [],
"Partner": null
}
}
您的代码似乎更像JavaScript-Object,如: - )
答案 1 :(得分:0)
您的回复是无效的JSON对象。
您可以通过某些在线工具验证JSON,例如http://jsonlint.com/
完整规范可以在RFC 7159 https://tools.ietf.org/html/rfc7159中找到。
基本上你应该看看如何以正确的方式将值编码为JSON格式。为此,您可以参考PHP Array to JSON Array using json_encode();
答案 2 :(得分:0)
private DataTable GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
return dt;
}
}
}
}