您的位置:首页 > 移动开发 > Android开发

android实现json数据的解析和把数据转换成json格式的字符串

2015-09-29 15:49 906 查看
利用android sdk里面的

JSONObject和JSONArray把集合或者普通数据,转换成json格式的字符串

JSONObject和JSONArray解析json格式的字符串为集合或者一般数据

代码:

<a target=_blank id="L1" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L1" rel="#L1" style="color: rgb(102, 102, 102); text-decoration: none;">   1</a>
<a target=_blank id="L2" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L2" rel="#L2" style="color: rgb(102, 102, 102); text-decoration: none;">   2</a>
<a target=_blank id="L3" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L3" rel="#L3" style="color: rgb(102, 102, 102); text-decoration: none;">   3</a>
<a target=_blank id="L4" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L4" rel="#L4" style="color: rgb(102, 102, 102); text-decoration: none;">   4</a>
<a target=_blank id="L5" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L5" rel="#L5" style="color: rgb(102, 102, 102); text-decoration: none;">   5</a>
<a target=_blank id="L6" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L6" rel="#L6" style="color: rgb(102, 102, 102); text-decoration: none;">   6</a>
<a target=_blank id="L7" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L7" rel="#L7" style="color: rgb(102, 102, 102); text-decoration: none;">   7</a>
<a target=_blank id="L8" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L8" rel="#L8" style="color: rgb(102, 102, 102); text-decoration: none;">   8</a>
<a target=_blank id="L9" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L9" rel="#L9" style="color: rgb(102, 102, 102); text-decoration: none;">   9</a>
<a target=_blank id="L10" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L10" rel="#L10" style="color: rgb(102, 102, 102); text-decoration: none;">  10</a>
<a target=_blank id="L11" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L11" rel="#L11" style="color: rgb(102, 102, 102); text-decoration: none;">  11</a>
<a target=_blank id="L12" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L12" rel="#L12" style="color: rgb(102, 102, 102); text-decoration: none;">  12</a>
<a target=_blank id="L13" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L13" rel="#L13" style="color: rgb(102, 102, 102); text-decoration: none;">  13</a>
<a target=_blank id="L14" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L14" rel="#L14" style="color: rgb(102, 102, 102); text-decoration: none;">  14</a>
<a target=_blank id="L15" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L15" rel="#L15" style="color: rgb(102, 102, 102); text-decoration: none;">  15</a>
<a target=_blank id="L16" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L16" rel="#L16" style="color: rgb(102, 102, 102); text-decoration: none;">  16</a>
<a target=_blank id="L17" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L17" rel="#L17" style="color: rgb(102, 102, 102); text-decoration: none;">  17</a>
<a target=_blank id="L18" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L18" rel="#L18" style="color: rgb(102, 102, 102); text-decoration: none;">  18</a>
<a target=_blank id="L19" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L19" rel="#L19" style="color: rgb(102, 102, 102); text-decoration: none;">  19</a>
<a target=_blank id="L20" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L20" rel="#L20" style="color: rgb(102, 102, 102); text-decoration: none;">  20</a>
<a target=_blank id="L21" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L21" rel="#L21" style="color: rgb(102, 102, 102); text-decoration: none;">  21</a>
<a target=_blank id="L22" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L22" rel="#L22" style="color: rgb(102, 102, 102); text-decoration: none;">  22</a>
<a target=_blank id="L23" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L23" rel="#L23" style="color: rgb(102, 102, 102); text-decoration: none;">  23</a>
<a target=_blank id="L24" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L24" rel="#L24" style="color: rgb(102, 102, 102); text-decoration: none;">  24</a>
<a target=_blank id="L25" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L25" rel="#L25" style="color: rgb(102, 102, 102); text-decoration: none;">  25</a>
<a target=_blank id="L26" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L26" rel="#L26" style="color: rgb(102, 102, 102); text-decoration: none;">  26</a>
<a target=_blank id="L27" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L27" rel="#L27" style="color: rgb(102, 102, 102); text-decoration: none;">  27</a>
<a target=_blank id="L28" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L28" rel="#L28" style="color: rgb(102, 102, 102); text-decoration: none;">  28</a>
<a target=_blank id="L29" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L29" rel="#L29" style="color: rgb(102, 102, 102); text-decoration: none;">  29</a>
<a target=_blank id="L30" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L30" rel="#L30" style="color: rgb(102, 102, 102); text-decoration: none;">  30</a>
<a target=_blank id="L31" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L31" rel="#L31" style="color: rgb(102, 102, 102); text-decoration: none;">  31</a>
<a target=_blank id="L32" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L32" rel="#L32" style="color: rgb(102, 102, 102); text-decoration: none;">  32</a>
<a target=_blank id="L33" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L33" rel="#L33" style="color: rgb(102, 102, 102); text-decoration: none;">  33</a>
<a target=_blank id="L34" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L34" rel="#L34" style="color: rgb(102, 102, 102); text-decoration: none;">  34</a>
<a target=_blank id="L35" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L35" rel="#L35" style="color: rgb(102, 102, 102); text-decoration: none;">  35</a>
<a target=_blank id="L36" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L36" rel="#L36" style="color: rgb(102, 102, 102); text-decoration: none;">  36</a>
<a target=_blank id="L37" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L37" rel="#L37" style="color: rgb(102, 102, 102); text-decoration: none;">  37</a>
<a target=_blank id="L38" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L38" rel="#L38" style="color: rgb(102, 102, 102); text-decoration: none;">  38</a>
<a target=_blank id="L39" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L39" rel="#L39" style="color: rgb(102, 102, 102); text-decoration: none;">  39</a>
<a target=_blank id="L40" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L40" rel="#L40" style="color: rgb(102, 102, 102); text-decoration: none;">  40</a>
<a target=_blank id="L41" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L41" rel="#L41" style="color: rgb(102, 102, 102); text-decoration: none;">  41</a>
<a target=_blank id="L42" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L42" rel="#L42" style="color: rgb(102, 102, 102); text-decoration: none;">  42</a>
<a target=_blank id="L43" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L43" rel="#L43" style="color: rgb(102, 102, 102); text-decoration: none;">  43</a>
<a target=_blank id="L44" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L44" rel="#L44" style="color: rgb(102, 102, 102); text-decoration: none;">  44</a>
<a target=_blank id="L45" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L45" rel="#L45" style="color: rgb(102, 102, 102); text-decoration: none;">  45</a>
<a target=_blank id="L46" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L46" rel="#L46" style="color: rgb(102, 102, 102); text-decoration: none;">  46</a>
<a target=_blank id="L47" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L47" rel="#L47" style="color: rgb(102, 102, 102); text-decoration: none;">  47</a>
<a target=_blank id="L48" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L48" rel="#L48" style="color: rgb(102, 102, 102); text-decoration: none;">  48</a>
<a target=_blank id="L49" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L49" rel="#L49" style="color: rgb(102, 102, 102); text-decoration: none;">  49</a>
<a target=_blank id="L50" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L50" rel="#L50" style="color: rgb(102, 102, 102); text-decoration: none;">  50</a>
<a target=_blank id="L51" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L51" rel="#L51" style="color: rgb(102, 102, 102); text-decoration: none;">  51</a>
<a target=_blank id="L52" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L52" rel="#L52" style="color: rgb(102, 102, 102); text-decoration: none;">  52</a>
<a target=_blank id="L53" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L53" rel="#L53" style="color: rgb(102, 102, 102); text-decoration: none;">  53</a>
<a target=_blank id="L54" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L54" rel="#L54" style="color: rgb(102, 102, 102); text-decoration: none;">  54</a>
<a target=_blank id="L55" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L55" rel="#L55" style="color: rgb(102, 102, 102); text-decoration: none;">  55</a>
<a target=_blank id="L56" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L56" rel="#L56" style="color: rgb(102, 102, 102); text-decoration: none;">  56</a>
<a target=_blank id="L57" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L57" rel="#L57" style="color: rgb(102, 102, 102); text-decoration: none;">  57</a>
<a target=_blank id="L58" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L58" rel="#L58" style="color: rgb(102, 102, 102); text-decoration: none;">  58</a>
<a target=_blank id="L59" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L59" rel="#L59" style="color: rgb(102, 102, 102); text-decoration: none;">  59</a>
<a target=_blank id="L60" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L60" rel="#L60" style="color: rgb(102, 102, 102); text-decoration: none;">  60</a>
<a target=_blank id="L61" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L61" rel="#L61" style="color: rgb(102, 102, 102); text-decoration: none;">  61</a>
<a target=_blank id="L62" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L62" rel="#L62" style="color: rgb(102, 102, 102); text-decoration: none;">  62</a>
<a target=_blank id="L63" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L63" rel="#L63" style="color: rgb(102, 102, 102); text-decoration: none;">  63</a>
<a target=_blank id="L64" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L64" rel="#L64" style="color: rgb(102, 102, 102); text-decoration: none;">  64</a>
<a target=_blank id="L65" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L65" rel="#L65" style="color: rgb(102, 102, 102); text-decoration: none;">  65</a>
<a target=_blank id="L66" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L66" rel="#L66" style="color: rgb(102, 102, 102); text-decoration: none;">  66</a>
<a target=_blank id="L67" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L67" rel="#L67" style="color: rgb(102, 102, 102); text-decoration: none;">  67</a>
<a target=_blank id="L68" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L68" rel="#L68" style="color: rgb(102, 102, 102); text-decoration: none;">  68</a>
<a target=_blank id="L69" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L69" rel="#L69" style="color: rgb(102, 102, 102); text-decoration: none;">  69</a>
<a target=_blank id="L70" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L70" rel="#L70" style="color: rgb(102, 102, 102); text-decoration: none;">  70</a>
<a target=_blank id="L71" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L71" rel="#L71" style="color: rgb(102, 102, 102); text-decoration: none;">  71</a>
<a target=_blank id="L72" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L72" rel="#L72" style="color: rgb(102, 102, 102); text-decoration: none;">  72</a>
<a target=_blank id="L73" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L73" rel="#L73" style="color: rgb(102, 102, 102); text-decoration: none;">  73</a>
<a target=_blank id="L74" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L74" rel="#L74" style="color: rgb(102, 102, 102); text-decoration: none;">  74</a>
<a target=_blank id="L75" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L75" rel="#L75" style="color: rgb(102, 102, 102); text-decoration: none;">  75</a>
<a target=_blank id="L76" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L76" rel="#L76" style="color: rgb(102, 102, 102); text-decoration: none;">  76</a>
<a target=_blank id="L77" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L77" rel="#L77" style="color: rgb(102, 102, 102); text-decoration: none;">  77</a>
<a target=_blank id="L78" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L78" rel="#L78" style="color: rgb(102, 102, 102); text-decoration: none;">  78</a>
<a target=_blank id="L79" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L79" rel="#L79" style="color: rgb(102, 102, 102); text-decoration: none;">  79</a>
<a target=_blank id="L80" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L80" rel="#L80" style="color: rgb(102, 102, 102); text-decoration: none;">  80</a>
<a target=_blank id="L81" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L81" rel="#L81" style="color: rgb(102, 102, 102); text-decoration: none;">  81</a>
<a target=_blank id="L82" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L82" rel="#L82" style="color: rgb(102, 102, 102); text-decoration: none;">  82</a>
<a target=_blank id="L83" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L83" rel="#L83" style="color: rgb(102, 102, 102); text-decoration: none;">  83</a>
<a target=_blank id="L84" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L84" rel="#L84" style="color: rgb(102, 102, 102); text-decoration: none;">  84</a>
<a target=_blank id="L85" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L85" rel="#L85" style="color: rgb(102, 102, 102); text-decoration: none;">  85</a>
<a target=_blank id="L86" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L86" rel="#L86" style="color: rgb(102, 102, 102); text-decoration: none;">  86</a>
<a target=_blank id="L87" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L87" rel="#L87" style="color: rgb(102, 102, 102); text-decoration: none;">  87</a>
<a target=_blank id="L88" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L88" rel="#L88" style="color: rgb(102, 102, 102); text-decoration: none;">  88</a>
<a target=_blank id="L89" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L89" rel="#L89" style="color: rgb(102, 102, 102); text-decoration: none;">  89</a>
<a target=_blank id="L90" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L90" rel="#L90" style="color: rgb(102, 102, 102); text-decoration: none;">  90</a>
<a target=_blank id="L91" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L91" rel="#L91" style="color: rgb(102, 102, 102); text-decoration: none;">  91</a>
<a target=_blank id="L92" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L92" rel="#L92" style="color: rgb(102, 102, 102); text-decoration: none;">  92</a>
<a target=_blank id="L93" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L93" rel="#L93" style="color: rgb(102, 102, 102); text-decoration: none;">  93</a>
<a target=_blank id="L94" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L94" rel="#L94" style="color: rgb(102, 102, 102); text-decoration: none;">  94</a>
<a target=_blank id="L95" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L95" rel="#L95" style="color: rgb(102, 102, 102); text-decoration: none;">  95</a>
<a target=_blank id="L96" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L96" rel="#L96" style="color: rgb(102, 102, 102); text-decoration: none;">  96</a>
<a target=_blank id="L97" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L97" rel="#L97" style="color: rgb(102, 102, 102); text-decoration: none;">  97</a>
<a target=_blank id="L98" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L98" rel="#L98" style="color: rgb(102, 102, 102); text-decoration: none;">  98</a>
<a target=_blank id="L99" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L99" rel="#L99" style="color: rgb(102, 102, 102); text-decoration: none;">  99</a>
<a target=_blank id="L100" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L100" rel="#L100" style="color: rgb(102, 102, 102); text-decoration: none;"> 100</a>
<a target=_blank id="L101" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L101" rel="#L101" style="color: rgb(102, 102, 102); text-decoration: none;"> 101</a>
<a target=_blank id="L102" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L102" rel="#L102" style="color: rgb(102, 102, 102); text-decoration: none;"> 102</a>
<a target=_blank id="L103" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L103" rel="#L103" style="color: rgb(102, 102, 102); text-decoration: none;"> 103</a>
<a target=_blank id="L104" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L104" rel="#L104" style="color: rgb(102, 102, 102); text-decoration: none;"> 104</a>
<a target=_blank id="L105" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L105" rel="#L105" style="color: rgb(102, 102, 102); text-decoration: none;"> 105</a>
<a target=_blank id="L106" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L106" rel="#L106" style="color: rgb(102, 102, 102); text-decoration: none;"> 106</a>
<a target=_blank id="L107" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L107" rel="#L107" style="color: rgb(102, 102, 102); text-decoration: none;"> 107</a>
<a target=_blank id="L108" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L108" rel="#L108" style="color: rgb(102, 102, 102); text-decoration: none;"> 108</a>
<a target=_blank id="L109" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L109" rel="#L109" style="color: rgb(102, 102, 102); text-decoration: none;"> 109</a>
<a target=_blank id="L110" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L110" rel="#L110" style="color: rgb(102, 102, 102); text-decoration: none;"> 110</a>
<a target=_blank id="L111" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L111" rel="#L111" style="color: rgb(102, 102, 102); text-decoration: none;"> 111</a>
<a target=_blank id="L112" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L112" rel="#L112" style="color: rgb(102, 102, 102); text-decoration: none;"> 112</a>
<a target=_blank id="L113" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L113" rel="#L113" style="color: rgb(102, 102, 102); text-decoration: none;"> 113</a>
<a target=_blank id="L114" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L114" rel="#L114" style="color: rgb(102, 102, 102); text-decoration: none;"> 114</a>
<a target=_blank id="L115" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L115" rel="#L115" style="color: rgb(102, 102, 102); text-decoration: none;"> 115</a>
<a target=_blank id="L116" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L116" rel="#L116" style="color: rgb(102, 102, 102); text-decoration: none;"> 116</a>
<a target=_blank id="L117" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L117" rel="#L117" style="color: rgb(102, 102, 102); text-decoration: none;"> 117</a>
<a target=_blank id="L118" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L118" rel="#L118" style="color: rgb(102, 102, 102); text-decoration: none;"> 118</a>
<a target=_blank id="L119" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L119" rel="#L119" style="color: rgb(102, 102, 102); text-decoration: none;"> 119</a>
<a target=_blank id="L120" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L120" rel="#L120" style="color: rgb(102, 102, 102); text-decoration: none;"> 120</a>
<a target=_blank id="L121" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L121" rel="#L121" style="color: rgb(102, 102, 102); text-decoration: none;"> 121</a>
<a target=_blank id="L122" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L122" rel="#L122" style="color: rgb(102, 102, 102); text-decoration: none;"> 122</a>
<a target=_blank id="L123" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L123" rel="#L123" style="color: rgb(102, 102, 102); text-decoration: none;"> 123</a>
<a target=_blank id="L124" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L124" rel="#L124" style="color: rgb(102, 102, 102); text-decoration: none;"> 124</a>
<a target=_blank id="L125" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L125" rel="#L125" style="color: rgb(102, 102, 102); text-decoration: none;"> 125</a>
<a target=_blank id="L126" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L126" rel="#L126" style="color: rgb(102, 102, 102); text-decoration: none;"> 126</a>
<a target=_blank id="L127" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L127" rel="#L127" style="color: rgb(102, 102, 102); text-decoration: none;"> 127</a>
<a target=_blank id="L128" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L128" rel="#L128" style="color: rgb(102, 102, 102); text-decoration: none;"> 128</a>
<a target=_blank id="L129" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L129" rel="#L129" style="color: rgb(102, 102, 102); text-decoration: none;"> 129</a>
<a target=_blank id="L130" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L130" rel="#L130" style="color: rgb(102, 102, 102); text-decoration: none;"> 130</a>
<a target=_blank id="L131" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L131" rel="#L131" style="color: rgb(102, 102, 102); text-decoration: none;"> 131</a>
<a target=_blank id="L132" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L132" rel="#L132" style="color: rgb(102, 102, 102); text-decoration: none;"> 132</a>
<a target=_blank id="L133" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L133" rel="#L133" style="color: rgb(102, 102, 102); text-decoration: none;"> 133</a>
<a target=_blank id="L134" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L134" rel="#L134" style="color: rgb(102, 102, 102); text-decoration: none;"> 134</a>
<a target=_blank id="L135" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L135" rel="#L135" style="color: rgb(102, 102, 102); text-decoration: none;"> 135</a>
<a target=_blank id="L136" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L136" rel="#L136" style="color: rgb(102, 102, 102); text-decoration: none;"> 136</a>
<a target=_blank id="L137" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L137" rel="#L137" style="color: rgb(102, 102, 102); text-decoration: none;"> 137</a>
<a target=_blank id="L138" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L138" rel="#L138" style="color: rgb(102, 102, 102); text-decoration: none;"> 138</a>
<a target=_blank id="L139" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L139" rel="#L139" style="color: rgb(102, 102, 102); text-decoration: none;"> 139</a>
<a target=_blank id="L140" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L140" rel="#L140" style="color: rgb(102, 102, 102); text-decoration: none;"> 140</a>
<a target=_blank id="L141" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L141" rel="#L141" style="color: rgb(102, 102, 102); text-decoration: none;"> 141</a>
<a target=_blank id="L142" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L142" rel="#L142" style="color: rgb(102, 102, 102); text-decoration: none;"> 142</a>
<a target=_blank id="L143" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L143" rel="#L143" style="color: rgb(102, 102, 102); text-decoration: none;"> 143</a>
<a target=_blank id="L144" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L144" rel="#L144" style="color: rgb(102, 102, 102); text-decoration: none;"> 144</a>
<a target=_blank id="L145" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L145" rel="#L145" style="color: rgb(102, 102, 102); text-decoration: none;"> 145</a>
<a target=_blank id="L146" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L146" rel="#L146" style="color: rgb(102, 102, 102); text-decoration: none;"> 146</a>
<a target=_blank id="L147" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L147" rel="#L147" style="color: rgb(102, 102, 102); text-decoration: none;"> 147</a>
<a target=_blank id="L148" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L148" rel="#L148" style="color: rgb(102, 102, 102); text-decoration: none;"> 148</a>
<a target=_blank id="L149" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L149" rel="#L149" style="color: rgb(102, 102, 102); text-decoration: none;"> 149</a>
<a target=_blank id="L150" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L150" rel="#L150" style="color: rgb(102, 102, 102); text-decoration: none;"> 150</a>
<a target=_blank id="L151" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L151" rel="#L151" style="color: rgb(102, 102, 102); text-decoration: none;"> 151</a>
<a target=_blank id="L152" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L152" rel="#L152" style="color: rgb(102, 102, 102); text-decoration: none;"> 152</a>
<a target=_blank id="L153" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L153" rel="#L153" style="color: rgb(102, 102, 102); text-decoration: none;"> 153</a>
<a target=_blank id="L154" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L154" rel="#L154" style="color: rgb(102, 102, 102); text-decoration: none;"> 154</a>
<a target=_blank id="L155" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L155" rel="#L155" style="color: rgb(102, 102, 102); text-decoration: none;"> 155</a>
<a target=_blank id="L156" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L156" rel="#L156" style="color: rgb(102, 102, 102); text-decoration: none;"> 156</a>
<a target=_blank id="L157" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L157" rel="#L157" style="color: rgb(102, 102, 102); text-decoration: none;"> 157</a>
<a target=_blank id="L158" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L158" rel="#L158" style="color: rgb(102, 102, 102); text-decoration: none;"> 158</a>
<a target=_blank id="L159" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L159" rel="#L159" style="color: rgb(102, 102, 102); text-decoration: none;"> 159</a>
<a target=_blank id="L160" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L160" rel="#L160" style="color: rgb(102, 102, 102); text-decoration: none;"> 160</a>
<a target=_blank id="L161" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L161" rel="#L161" style="color: rgb(102, 102, 102); text-decoration: none;"> 161</a>
<a target=_blank id="L162" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L162" rel="#L162" style="color: rgb(102, 102, 102); text-decoration: none;"> 162</a>
<a target=_blank id="L163" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L163" rel="#L163" style="color: rgb(102, 102, 102); text-decoration: none;"> 163</a>
<a target=_blank id="L164" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L164" rel="#L164" style="color: rgb(102, 102, 102); text-decoration: none;"> 164</a>
<a target=_blank id="L165" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L165" rel="#L165" style="color: rgb(102, 102, 102); text-decoration: none;"> 165</a>
<a target=_blank id="L166" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L166" rel="#L166" style="color: rgb(102, 102, 102); text-decoration: none;"> 166</a>
<a target=_blank id="L167" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L167" rel="#L167" style="color: rgb(102, 102, 102); text-decoration: none;"> 167</a>
<a target=_blank id="L168" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L168" rel="#L168" style="color: rgb(102, 102, 102); text-decoration: none;"> 168</a>
<a target=_blank id="L169" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L169" rel="#L169" style="color: rgb(102, 102, 102); text-decoration: none;"> 169</a>
<a target=_blank id="L170" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L170" rel="#L170" style="color: rgb(102, 102, 102); text-decoration: none;"> 170</a>
<a target=_blank id="L171" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L171" rel="#L171" style="color: rgb(102, 102, 102); text-decoration: none;"> 171</a>
<a target=_blank id="L172" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L172" rel="#L172" style="color: rgb(102, 102, 102); text-decoration: none;"> 172</a>
<a target=_blank id="L173" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L173" rel="#L173" style="color: rgb(102, 102, 102); text-decoration: none;"> 173</a>
<a target=_blank id="L174" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L174" rel="#L174" style="color: rgb(102, 102, 102); text-decoration: none;"> 174</a>
<a target=_blank id="L175" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L175" rel="#L175" style="color: rgb(102, 102, 102); text-decoration: none;"> 175</a>
<a target=_blank id="L176" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L176" rel="#L176" style="color: rgb(102, 102, 102); text-decoration: none;"> 176</a>
<a target=_blank id="L177" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L177" rel="#L177" style="color: rgb(102, 102, 102); text-decoration: none;"> 177</a>
<a target=_blank id="L178" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L178" rel="#L178" style="color: rgb(102, 102, 102); text-decoration: none;"> 178</a>
<a target=_blank id="L179" href="http://blog.csdn.net/hhhccckkk/article/details/16859927#L179" rel="#L179" style="color: rgb(102, 102, 102); text-decoration: none;"> 179</a>
package com.hck.test;
import java.util.ArrayList;import java.util.List;
import org.json.JSONArray;import org.json.JSONException;import org.json.JSONObject;
import android.app.Activity;import android.os.Bundle;import android.util.Log;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;import android.widget.Toast;
public class MainActivity extends Activity implements OnClickListener { private Button button1, button2, button3, button4; //4个按钮 private TextView textView; //显示处理结果的textview private List<UserBean> userBeans; //保存数据的集合 private JSONObject object; //JSONObject对象,处理一个一个的对象 private JSONObject object2; private JSONArray jsonArray;//JSONObject对象,处理一个一个集合或者数组 private String jsonString; //保存带集合的json字符串 private String jsonString2;//不带集合的json字符串 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); initView(); //初始化控件 initDate(); //初始化数据 setListener(); //绑定监事件
}
private void initView() { button1 = (Button) findViewById(R.id.bt1); button2 = (Button) findViewById(R.id.bt2); button3 = (Button) findViewById(R.id.bt3); button4 = (Button) findViewById(R.id.bt4); textView = (TextView) findViewById(R.id.text); }/** * 初始化2个用户对象 */ private void initDate() { userBeans = new ArrayList<UserBean>(); UserBean userBean = new UserBean(); userBean.setUserId(1); userBean.setUserName("hck"); userBeans.add(userBean);
UserBean userBean2 = new UserBean(); userBean2.setUserId(2); userBean2.setUserName("蝌蚪"); userBeans.add(userBean2);
}
private void setListener() { button1.setOnClickListener(this); button2.setOnClickListener(this); button3.setOnClickListener(this); button4.setOnClickListener(this); }
private void changeArrayDateToJson() { //把一个集合转换成json格式的字符串 jsonArray=null; object=null; jsonArray = new JSONArray(); object=new JSONObject(); for (int i = 0; i < userBeans.size(); i++) { //遍历上面初始化的集合数据,把数据加入JSONObject里面 object2 = new JSONObject();//一个user对象,使用一个JSONObject对象来装 try { object2.put("userId", userBeans.get(i).getUserId()); //从集合取出数据,放入JSONObject里面 JSONObject对象和map差不多用法,以键和值形式存储数据 object2.put("userName", userBeans.get(i).getUserName()); jsonArray.put(object2); //把JSONObject对象装入jsonArray数组里面 } catch (JSONException e) { e.printStackTrace(); } } try { object.put("userDate", jsonArray); //再把JSONArray数据加入JSONObject对象里面(数组也是对象) //object.put("time", "2013-11-14"); //这里还可以加入数据,这样json型字符串,就既有集合,又有普通数据 } catch (JSONException e) { e.printStackTrace(); } jsonString=null; jsonString = object.toString(); //把JSONObject转换成json格式的字符串 textView.setText(jsonString); Log.i("hck", "转换成json字符串: " + jsonString);
} private void changeNotArrayDateToJson() { object=null; object=new JSONObject(); try { object.put("userId", "1"); //把数据加入JSONObject对象即可,"userid"相当于map里面的key,1即为value的值。 object.put("userName", "hck"); } catch (JSONException e) { e.printStackTrace(); } jsonString2=null; jsonString2 = object.toString();//把JSONObject转换成json格式的字符串 Log.i("hck", "转换成json字符串: " + jsonString2); textView.setText(jsonString2); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.bt1: changeNotArrayDateToJson(); //点击第一个按钮,把集合转换成json数据格式的string break;
case R.id.bt2: changeArrayDateToJson(); //点击第2个按钮,把普通数据换成json数据格式的string break; case R.id.bt3: //解析不带集合的json字符串 if (jsonString2==null || "".equals(jsonString2)) { Toast.makeText(MainActivity.this, "请先点击上面第1个按钮转把数据换成json字符串", Toast.LENGTH_LONG).show(); return; } changeJsonToData2(); break; case R.id.bt4://解析带集合的json字符串 if (jsonString==null || "".equals(jsonString)) { Toast.makeText(MainActivity.this, "请先点击第2按钮把数据换成json字符串", Toast.LENGTH_LONG).show(); return; } changeJsonToData1(); break; default: break; }
} private void changeJsonToData1() { StringBuilder stringBuilder=new StringBuilder(); //用来保存解析出来的额数据,显示在textview UserBean userBean; List<UserBean> bList=new ArrayList<UserBean>(); try { object=new JSONObject(jsonString); //用json格式的字符串获取一个JSONObject对象 jsonArray=object.getJSONArray("userDate"); //通过key,获取JSONObject里面的一个JSONArray数组 for (int i = 0; i < jsonArray.length(); i++) { //遍历数据 object=jsonArray.getJSONObject(i); //从JSONArray里面获取一个JSONObject对象 userBean=new UserBean(); userBean.setUserId(object.getInt("userId")); //通过key,获取里面的数据 userBean.setUserName(object.getString("userName")); bList.add(userBean); } } catch (JSONException e) { e.printStackTrace(); } for (int i = 0; i < bList.size(); i++) { stringBuilder.append("用户id:"+bList.get(i).getUserId()).append(" ").append("用户名字:"+bList.get(i).getUserName()); } textView.setText(stringBuilder.toString().replace("null", "")); } private void changeJsonToData2() { try { object=new JSONObject(jsonString2); String userName=object.getString("userName"); String userIdString=object.getString("userId"); textView.setText("用户id"+userIdString+"用户名字:"+userName); } catch (JSONException e) { e.printStackTrace(); } }}


 来自CODE的代码片
jsonTodate

 

版权声明:本文为博主原创文章,未经博主允许不得转载。from:http://blog.csdn.net/hhhccckkk/article/details/16859927
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: