2011-03-21 116 views
0

我正在使用此查询从Web服务器将数据提取到我的iPhone应用程序使用JSON解析。从Web服务器提取数据到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 
    ) 

理想的情况下,它应该返回数据,如

enter image description here

但它显示的列PointsStrike垃圾值(如 “MA ==” 等)。

什么可能是错的?

编辑:

我使用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价值

{"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"}]} 

这是数据表:

enter image description here

在应用方面我我使用

NSDictionary *diction = [responseString JSONValue]; 

注:当服务器上执行查询工作正常。

回答

1

改变了我的查询到

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 
) 

只是删除了单引号括起来的十进制值'

+0

不错的工作!自己找到答案总是更令人满意。 – 2011-03-21 21:24:55

+0

是的非常真实!谢谢 :) – 2011-03-22 04:42:45

1

在到达您的iPhone之前,在每个点进行故障排除。如果你在数据库主机上运行查询,你会得到什么?如果您通过Web服务器运行查询,您会得到什么JSON响应?

另外,你用什么框架来解析JSON?通过代码片段粘贴来显示您如何解析响应可能有助于提供更有针对性的答案。

+0

感谢您的快速输入。我会尽快添加代码 – 2011-03-21 10:16:37

+0

我正在使用SBJSON解析器。我编辑了我的问题并添加了处理JSON解析的代码。 – 2011-03-21 10:35:57

+0

你发送给iPhone的是什么JSON字符串? (finalString在发送到iPhone之前的值是多少?) – 2011-03-21 11:00:37