从 Web 服务器获取数据到 iPhone 会返回垃圾值

发布于 2024-10-24 22:10:52 字数 2227 浏览 1 评论 0原文

我正在使用此查询使用 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==”等) PointsStrike 列。

可能出什么问题了?

编辑:

我正在使用 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

enter image description here

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:

enter image description here

On app side I am using

NSDictionary *diction = [responseString JSONValue];

NOTE: The Query works fine when executed on server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

网名女生简单气质 2024-10-31 22:10:52

在问题到达您的 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.

ぶ宁プ宁ぶ 2024-10-31 22:10:52

将我的查询更改为

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
)

“仅删除十进制值周围的单引号 '”。

Changed my Query to

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
)

Just removed the single quotes ' around the decimal values.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文