【问题标题】:JSON data in sectionedTableView iPhonesectionedTableView iPhone 中的 JSON 数据
【发布时间】:2012-04-12 13:21:06
【问题描述】:

我从我的 mysql 数据库中接收客户数据。我想在分段表视图中显示所有客户。每个部分的标题是客户姓名的第一个字母,每个部分中的 numberOfrows 是以相同字母开头的客户数。基本上它应该看起来像我 iPhone 上的联系人应用程序。

这是我的数据http://mobile.beger.org/getdata.php53?object=customer&mode=all

现在我可以在我的 tableView 中显示所有客户。我怎样才能把客户分成几个部分? 我必须编辑我的mysql选择吗?或者我应该有两个 json 字符串。一个是每封信和以这封信开头的客户数量,另一个是客户详细信息?

感谢您的帮助!

【问题讨论】:

    标签: iphone mysql objective-c json uitableview


    【解决方案1】:

    您正在使用这种块来获得简单且便宜的解决方案。我已编辑您的网络服务响应。请看一下。

    {
      "customer": [
        { "A": [
          {
            "i_customer_m": "22",
            "s_name1": "Amann Solutions AG",
            "s_town": "Herisau"
          },
          {
            "i_customer_m": "5",
            "s_name1": "Architekturhaus Leibold GmbH",
            "s_town": "D\u00fcnkelsried"
          },
          {
            "i_customer_m": "68",
            "s_name1": "ATEcare Service GmbH & Co.KG",
            "s_town": "Aichach"
          },
          {
            "i_customer_m": "83",
            "s_name1": "Autohandel Polska GmbH",
            "s_town": "Prag"
          },
          {
            "i_customer_m": "65",
            "s_name1": "Autohandel Polska GmbH",
            "s_town": "Prag"
          }
        ]},
        {"B": [
          {
            "i_customer_m": "45",
            "s_name1": "Baugenossenschaft Strassbourgh",
            "s_town": "Strassbourgh"
          },
          {
            "i_customer_m": "11",
            "s_name1": "Baugenossenschaft Wien",
            "s_town": "Wien"
          },
          {
            "i_customer_m": "1",
            "s_name1": "Betzy AG",
            "s_town": "Germering, Oberbayern"
          },
          {
            "i_customer_m": "46",
            "s_name1": "BSG",
            "s_town": "Herrsching am Ammersee"
          },
          {
            "FirstLetter": "B",
            "i_customer_m": "67",
            "s_name1": "BVVS Systemhaus GmbH",
            "s_town": "M\u00fcnchen"
          }
        ]}
      ]
    }
    

    谢谢,

    【讨论】:

    • 由此我们也减少了数据冗余。并获得更快的响应。
    • 感谢您的回答!那么如何更改我的 mysql/php 代码以使其看起来像你的呢?这里是 $rs = mysql_query("SELECT LEFT(CUSTOMER_M.s_name1,1) as FirstLetter,CUSTOMER_M.i_customer_m, CUSTOMER_M.s_name1, COALESCE(CUSTOMER_M.s_town,'unbekannt') as s_town FROM CUSTOMER_M WHERE CUSTOMER_M.I_CUSTOMER_M > 0 客户订购_M.S_NAME1");而($obj = mysql_fetch_object($rs)) { $arr[] = $obj; } echo '{"customer":'.json_encode($arr).'}';
    • 将 JSON 格式化为代码(突出显示它并按下 {} 按钮)。这样格式就被保留了(这次我已经为你做了)。
    • 感谢您的建议 :) 我很乐意这样做,但我可以回答我自己的问题。在评论框中,我无法使用代码{}功能!
    • 我从上面检查了 json 代码。它无效吗?我确实明白它应该做什么,但它没有。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-04
    • 1970-01-01
    相关资源
    最近更新 更多