从 Web 服务器获取数据到 iPhone 会返回垃圾值
我正在使用此查询使用 JSON 解析从网络服务器获取数据到我的 iPhone 应用程序。
SELECT a.FundID, a.FundName, a.Strike, a.LongShort, a.Current, a.Points, a.OpenClose
FROM tbl_Positions a, tbl_FundStatic b
WHERE b.FundID = a.FundID
AND b.UserID = '14'
AND a.OpenClose != 'Close'
UNION
SELECT c.FundID, c.FundName, '0' AS Strike, "-" AS LongShort, b.LastTradePrice, '0' AS Points, "-" AS OpenClose
FROM tbl_FundStatic c, tbl_MarketData b
WHERE c.UserID = '14'
AND b.IndexCode = c.`Index`
AND c.FundID NOT
IN (
SELECT DISTINCT (FundID)
FROM tbl_Positions
)
的数据
理想情况下,它应该返回类似
,但它显示垃圾值(如“MA==”等) Points
和 Strike
列。
可能出什么问题了?
编辑:
我正在使用 SBJSON 解析器。
我使用以下代码在服务器端将数据解析为 JSON 字符串:
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
objMyCon.Close();
String jsonString = JsonConvert.SerializeObject(dt);
String finalString = "{\"ExecuteTrade\":";
finalString += jsonString;
finalString += "}";
return finalString;
finalString Value
{"ExecuteTrade":[{"FundID":28,"FundName":"Sam Fund 2","Strike":"MTIxMzA=","LongShort":"Long","Current":11985.00,"Points":"LTE0NQ==","OpenClose":"Open"},
{"FundID":27,"FundName":"Sam Fund 1","Strike":"MTE5ODU=","LongShort":"Long","Current":11985.00,"Points":"NTAwMDA=","OpenClose":"Open"},
{"FundID":32,"FundName":"Sam Fund 3","Strike":"MjIwMDA=","LongShort":"Long","Current":14000.00,"Points":"NjAwMA==","OpenClose":"Open"},
{"FundID":45,"FundName":"Rob Fund test","Strike":"OTk5OQ==","LongShort":"NULL","Current":11984.61,"Points":"OTk5OQ==","OpenClose":"NULL"},
{"FundID":46,"FundName":"newtestfund5th","Strike":"OTk5OQ==","LongShort":"NULL","Current":11984.61,"Points":"OTk5OQ==","OpenClose":"NULL"}]}
这是数据表:
在应用程序端,我使用
NSDictionary *diction = [responseString JSONValue];
注意: 查询在服务器上执行时工作正常。
I am using this query to fetch data from webserver onto my iPhone app using JSON Parsing.
SELECT a.FundID, a.FundName, a.Strike, a.LongShort, a.Current, a.Points, a.OpenClose
FROM tbl_Positions a, tbl_FundStatic b
WHERE b.FundID = a.FundID
AND b.UserID = '14'
AND a.OpenClose != 'Close'
UNION
SELECT c.FundID, c.FundName, '0' AS Strike, "-" AS LongShort, b.LastTradePrice, '0' AS Points, "-" AS OpenClose
FROM tbl_FundStatic c, tbl_MarketData b
WHERE c.UserID = '14'
AND b.IndexCode = c.`Index`
AND c.FundID NOT
IN (
SELECT DISTINCT (FundID)
FROM tbl_Positions
)
Ideally it should return data like
But it shows junk value (like "MA==",etc) for the columns Points
and Strike
.
What could be wrong?
EDIT:
I am using SBJSON Parser.
I am using following code to parse data into JSON String on server side:
DataTable dt = new DataTable();
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
da.Fill(dt);
objMyCon.Close();
String jsonString = JsonConvert.SerializeObject(dt);
String finalString = "{\"ExecuteTrade\":";
finalString += jsonString;
finalString += "}";
return finalString;
finalString Value
{"ExecuteTrade":[{"FundID":28,"FundName":"Sam Fund 2","Strike":"MTIxMzA=","LongShort":"Long","Current":11985.00,"Points":"LTE0NQ==","OpenClose":"Open"},
{"FundID":27,"FundName":"Sam Fund 1","Strike":"MTE5ODU=","LongShort":"Long","Current":11985.00,"Points":"NTAwMDA=","OpenClose":"Open"},
{"FundID":32,"FundName":"Sam Fund 3","Strike":"MjIwMDA=","LongShort":"Long","Current":14000.00,"Points":"NjAwMA==","OpenClose":"Open"},
{"FundID":45,"FundName":"Rob Fund test","Strike":"OTk5OQ==","LongShort":"NULL","Current":11984.61,"Points":"OTk5OQ==","OpenClose":"NULL"},
{"FundID":46,"FundName":"newtestfund5th","Strike":"OTk5OQ==","LongShort":"NULL","Current":11984.61,"Points":"OTk5OQ==","OpenClose":"NULL"}]}
This is the Datatable:
On app side I am using
NSDictionary *diction = [responseString JSONValue];
NOTE: The Query works fine when executed on server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在问题到达您的 iPhone 之前,逐一排除故障。如果您在数据库主机上运行查询,您会得到什么?如果您通过 Web 服务器运行查询,您会得到什么 JSON 响应?
另外,你用什么框架来解析 JSON?粘贴显示如何解析响应的代码片段可能有助于提供更有针对性的答案。
Troubleshoot at each point, before it gets to your iPhone. If you run the query on the database host, what do you get? If you run the query through your web server, what JSON response do you get?
Also, what framework are you using to parse the JSON? Pasting in a code snippet that shows how you're parsing the response may help give more focused answers.
将我的查询更改为
“仅删除十进制值周围的单引号
'
”。Changed my Query to
Just removed the single quotes
'
around the decimal values.