NutzCN Logo
问答 想问一下这个第三方接口返回的值用什么来接收?
发布于 2034天前 作者 qq_722cb381 1463 次浏览 复制 上一个帖子 下一个帖子
标签:

下面的数据使用 流来接收的,用request.getParameter("address"); 接收都是null。

------------------------------020b661b3d6eContent-Disposition:
 form-data; 
 name="add_time"1555917934------------------------------020b661b3d6eContent-Disposition: form-data; 
 name="addr_id"19857------------------------------020b661b3d6eContent-Disposition: form-data; 
 name="address"北京市朝阳区安苑北里居住区22号楼安苑北里22号楼311------------------------------020b661b3d6eContent-Disposition: form-data;
 name="area_id"110105------------------------------020b661b3d6eContent-Disposition: form-data; 
 name="city_id"110100------------------------------020b661b3d6eContent-Disposition: form-data; 
 name="commercial_divide_money"0.00------------------------------020b661b3d6eContent-Disposition: form-data; name="commercial_divide_type"0------------------------------020b661b3d6eContent-Disposition: form-data; name="commercial_id"0------------------------------020b661b3d6eContent-Disposition: form-data; name="confuse_time"0------------------------------020b661b3d6eContent-Disposition: form-data; name="consignee"胡------------------------------020b661b3d6eContent-Disposition: form-data; name="delivery_time"0------------------------------020b661b3d6eContent-Disposition: form-data; name="divide_money"0.00------------------------------020b661b3d6eContent-Disposition: form-data; name="driver_id"0------------------------------020b661b3d6eContent-Disposition: form-data; name="hire_price"0.00------------------------------020b661b3d6eContent-Disposition: form-data; name="is_prepare"1------------------------------020b661b3d6eContent-Disposition: form-data; name="latitude"39.990492979621------------------------------020b661b3d6eContent-Disposition: form-data; name="longitude"116.41574085078128------------------------------020b661b3d6eContent-Disposition: form-data; name="mobile"15101570465------------------------------020b661b3d6eContent-Disposition: form-data; name="order_direction"1------------------------------020b661b3d6eContent-Disposition: form-data; name="order_id"101507------------------------------020b661b3d6eContent-Disposition: form-data; name="order_note"------------------------------020b661b3d6eContent-Disposition: form-data; name="order_sn"ss31170115253559------------------------------020b661b3d6eContent-Disposition: form-data; name="order_status"1------------------------------020b661b3d6eContent-Disposition: form-data; name="order_trade"I00000000155591795223534------------------------------020b661b3d6eContent-Disposition: form-data; name="order_type"0------------------------------020b661b3d6eContent-Disposition: form-data; name="pay_balance"0.00------------------------------020b661b3d6eContent-Disposition: form-data; name="pay_recovery"0.01------------------------------020b661b3d6eContent-Disposition: form-data; name="pay_status"2------------------------------020b661b3d6eContent-Disposition: form-data; name="pay_time"1555917963------------------------------020b661b3d6eContent-Disposition: form-data; name="pay_type"2------------------------------020b661b3d6eContent-Disposition: form-data; name="reason"------------------------------020b661b3d6eContent-Disposition: form-data; name="send_end_time"0------------------------------020b661b3d6eContent-Disposition: form-data; name="send_start_time"0------------------------------020b661b3d6eContent-Disposition: form-data; name="sign_time"0------------------------------020b661b3d6eContent-Disposition: form-data; name="store_id"311701------------------------------020b661b3d6eContent-Disposition: form-data; name="total_fee"0.01------------------------------020b661b3d6eContent-Disposition: form-data; name="total_profit"0.00------------------------------020b661b3d6eContent-Disposition: form-data; name="user_id"3092003------------------------------020b661b3d6eContent-Disposition: form-data; name="message"您在嗖嗖平台有新订单来了~------------------------------020b661b3d6eContent-Disposition: form-data; name="unique_iden"------------------------------020b661b3d6e--

16 回复
@AdaptBy(type = JsonAdaptor.class)
public void a(@Param("..") NutMap map)

@Wizzercn 我是直接这么获取map.get("address");?试了一下好像有问题

@Wizzercn NutMap应该是一个实体对吧

Json.toJson 打印看看呗

加上@AdaptBy(type = JsonAdaptor.class) 走方法就报错了

04-22 15:55:38.369  WARN  - [FailProcessor.http-bio-8080-exec-5] Error@/order/newOrderNoticeBack :
java.lang.NumberFormatException
	at java.math.BigDecimal.<init>(BigDecimal.java:470)
	at java.math.BigDecimal.<init>(BigDecimal.java:739)
	at org.nutz.json.impl.JsonTokenScan.readObject(JsonCompileImplV2.java:283)
	at org.nutz.json.impl.JsonTokenScan.read(JsonCompileImplV2.java:353)
	at org.nutz.json.impl.JsonCompileImplV2.parse(JsonCompileImplV2.java:26)
	at org.nutz.json.Json.fromJson(Json.java:40)
	at org.nutz.mvc.adaptor.JsonAdaptor.getReferObject(JsonAdaptor.java:41)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:216)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:113)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:40)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:183)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1082)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:744)

去掉JsonAdaptor 直接接收打印呢

@Wizzercn 能进方法 打印是这个,也不对啊

{
   "id" :0,
   "storeId" :0,
   "noticetype" :0,
   "isdetele" :0
}

文档上也是这么写的,加了@AdaptBy(type=JsonAdaptor.class) ,@Param("..")User user 实体类接收

服务器端的入口方法

@AdaptBy(type=JsonAdaptor.class)
@At("/user/update")
@Ok("json:{locked:'password|salt'}")
public Object update(@Param("..")User user) {
    NutMap re = new NutMap();
    if (user == null || user.getId() < 1) {
        re.put("ok", false);
        re.put("msg", "null object");
        return re;
    }
    int count = dao.update(user);
    if (count != 1) {
        re.put("ok", false);
        re.put("msg", "no user match");
        return re;
    }
    re.put("data", dao.fetch(User.class, user.getId));
    re.put("ok", true);
    return re;
}

@Wizzercn 为什么加上适配器就报错呢?@AdaptBy(type = JsonAdaptor.class) 加这个Debug都进不去

@Wizzercn json字符串里 有几个字段没传会有影响吗?

不是json, 是文件上传, 用WhaleAdatpor或者UploadAdaptor

对方给我传的是这个,不是文件上传,我需要接收这个json。

  {
    "address": "北京市朝阳区静安里30号桔子酒店精选(北京三元桥店)408",//收货地址
    "consignee": "大勇啊",//收货人名称
    "mobile": "17310509897",//收货人手机
    "order_id": "79020",//订单id
    "store_id": 11,//店铺id
    "order_sn": "ss4323163613",//订单号
    "order_status": "4",//订单状态
    "total_fee": "0.01",//订单金额
    "message": "您在嗖嗖平台有新订单来了~",//新订单描述文案
    "unique_iden": "SSKP"//嗖嗖在第三方的标识
  }

@wendal 加上@AdaptBy(type = JsonAdaptor.class) 就报错,哎

你最初发的那个数据, 是mulitpart-form, 文件上传时用的格式

并不是json数据,当然报错

@wendal 嗯嗯,可以了,感谢大佬

添加回复
请先登陆
回到顶部