码迷,mamicode.com
首页 > 移动开发 > 详细

输出Bag中的所有记录为一个json数组---精通android、IOS App应用服务程序开发

时间:2015-05-31 06:47:54      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:android   json   ios   app   应用   

书写闭合的json格式内容

{“item”:
    {
<chtml>
… …
</chtml>
    } ,"tatol":@{item:getLength}
}

与内层的标签运行结果共同组织一个完整的json格式文本输出到Android(IOS) App

"tatol":@{item:getLength}

为统计记录数

初始化Bag中的记录
同上一博
(您也可以从数据库中查询,如)

<esql module=help id=item>Select    ID,Subject,Writer,DayTime,Body  From        Messages</esql>

输出Bag中的所有记录

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

list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等)

结果

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

完整代码

{"items":{
<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}">
    <!-- list属性参数表示输出为数组列表格式,end属性参数表示数组结束的位置(跟for的end值相等) -->
        <name>@{item:name}</name>
        <price value>@{item:price}</price><!-- value属性参数表示输出不带引号的值 -->
        <unit>@{item:unit}</unit>
    </item>
</for>
</chtml>
},"tatol":@{item:getLength}
}

例子文件_samples/app/one_array.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

输出Bag中的所有记录为一个json数组---精通android、IOS App应用服务程序开发

标签:android   json   ios   app   应用   

原文地址:http://blog.csdn.net/tx18/article/details/46284369

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!