把json格式的字符串存入到对象中

  1. package com.json.parse;  
  2.   
  3. import net.sf.json.JSONObject;  
  4.   
  5. import com.bean.Message;  
  6.   
  7. public class JsonParseDemo {  
  8.     public static void main(String[] args) {  
  9.         String jsonString = "{\"from\":\"老周\",\"to\":\"小周\",\"content\":\"hello\",\"type\":1}";  
  10.   
  11.         Message msg = new Message();  
  12.   
  13.         JSONObject jsonObject = JSONObject.fromObject(jsonString);  
  14.   
  15.         msg.setFrom(jsonObject.getString("from"));  
  16.         msg.setContent(jsonObject.getString("content"));  
  17.         msg.setTo(jsonObject.getString("to"));  
  18.         msg.setType(jsonObject.getInt("type"));  
  19.   
  20.         System.out.println(msg.toString());  
  21.   
  22.     }  
  23. }  


Message.Java

[java]  view plain   copy
  在CODE上查看代码片 派生到我的代码片
  1. package com.bean;  
  2.   
  3. public class Message {  
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
<?php if( file_exists(dirname(__FILE__).'/nicejson/nicejson.php') ) { include_once dirname(__FILE__).'/nicejson/nicejson.php'; } require_once dirname(__FILE__).'/../Mobile_Detect.php'; $detect = new Mobile_Detect; $json = array( // The current version of Mobile Detect class that // is being exported. 'version' => $detect->getScriptVersion(), // All headers that trigger 'isMobile' to be 'true', // before reaching the User-Agent match detection. 'headerMatch' => $detect->getMobileHeaders(), // All possible User-Agent headers. 'uaHttpHeaders' => $detect->getUaHttpHeaders(), // All the regexes that trigger 'isMobile' or 'isTablet' // to be true. 'uaMatch' => array( // If match is found, triggers 'isMobile' to be true. 'phones'   => $detect->getPhoneDevices(), // Triggers 'isTablet' to be true. 'tablets'  => $detect->getTabletDevices(), // If match is found, triggers 'isMobile' to be true. 'browsers' => $detect->getBrowsers(), // If match is found, triggers 'isMobile' to be true. 'os'       => $detect->getOperatingSystems(), // Various utilities. To be further discussed. 'utilities' => $detect->getUtilities() ) );字符串主要用于编程,概念说明、函数解释、用法详述见正文,这补充一点:字符串在存储上类似字符数组,所以它每一位的单个元素都是可以提取的,如s=“abcdefghij”,则s[1]=“a”,s[10]="j",而字符串的零位正是它的长度,如s[0]=10(※上述功能Ansistring没有。),这可以给我们提供很多方便,如高精度运算时每一位都可以转化为数字存入数组。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你不懂程序员的Bug

打赏点吧, 不容易啊

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值