nokey属性(输出没有名称的数组)---精通android、IOS App应用服务程序开发

来源:互联网 发布:方维o2o上门服务 源码 编辑:程序博客网 时间:2024/05/21 19:22

输出没有名称的数组

闭合的json格式内容
不需要

初始化Bag中的记录
同上一博(也可见下边完整代码相关部分)

输出Bag中的所有记录,不输出数组名称

<for bags=item end="@{item:getLength}">    <item list="@{item:getSuffix}" end="@{item:getLength}" nokey>    <!-- list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等), nokey属性参数表示不输出数组名称-->        <name>@{item:name}</name>        <price value>@{item:price}</price><!-- value属性参数表示输出不带引号的值 -->        <unit>@{item:unit}</unit>    </item></for>

nokey属性参数表示不输出数组名称

结果

[{"name":"土豆","price":1.24,"unit":"KG"},{"name":"T恤","price":68,"unit":"件"},{"name":"可乐","price":2.20,"unit":"瓶"},{"name":"书","price":51.24,"unit":"本"}]

完整代码

<chtml><!-- 数据准备部分,您可以从数据库中查询 --><bag id=item suffix=0>    <we name=name>土豆</we>    <we name=price>1.24</we>    <we name=unit>KG</we></bag><bag id=item suffix=1>    <we name=name>T恤</we>    <we name=price>68</we>    <we name=unit></we></bag><bag id=item suffix=2>    <we name=name>可乐</we>    <we name=price>2.20</we>    <we name=unit></we></bag><bag id=item suffix=3>    <we name=name></we>    <we name=price>51.24</we>    <we name=unit></we></bag></chtml><chtml><!-- 正式json格式的内容 --><for bags=item end="@{item:getLength}">    <item list="@{item:getSuffix}" end="@{item:getLength}" nokey>    <!-- list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等), nokey属性参数表示不输出数组名称-->        <name>@{item:name}</name>        <price value>@{item:price}</price><!-- value属性参数表示输出不带引号的值 -->        <unit>@{item:unit}</unit>    </item></for></chtml>

例子文件_samples/app/one_array_nokey.json在轻开平台的_samples/app/目录下

相关资源下载:
移动App应用服务器开发从入门到精通:http://download.csdn.net/detail/tx18/8741611
快速搭建移动App服务器 :http://download.csdn.net/detail/tx18/8737507
轻开平台会不定期升级为大家提供更多强大而Easy的功能,请留意下载最新的版本:http://download.csdn.net/user/tx18

5 3