我需要在web api中使用接收json的方法,但其结构是动态的。我尝试使用以下代码,但值始终为null。
(ql:quickload :cffi)
(cffi:load-foreign-library "user32.dll")
(cffi:load-foreign-library "kernel32.dll")
(cffi:load-foreign-library "msvcrt.dll")
(cffi:defcfun ("GetClipboardData" get-clip) :string
(uformat :unsigned-int))
(cffi:defcfun ("OpenClipboard" open-clip) :int
(hOwner :unsigned-int))
(cffi:defcfun ("CloseClipboard" close-clip) :int
(hOwner :unsigned-int))
(cffi:defcfun ("EmptyClipboard" empty-clip) :int)
(cffi:defcfun ("SetClipboardData" set-clip) :int
(data :unsigned-int)
(format :unsigned-int))
(cffi:defcfun ("GlobalAlloc" global-alloc) :int
(flags :unsigned-int)
(numbytes :unsigned-int))
(cffi:defcfun ("GlobalLock" global-lock) :unsigned-int
(typ :unsigned-int))
(cffi:defcfun ("GlobalLock" global-lock-string) :string
(typ :unsigned-int))
(cffi:defcfun ("GlobalUnlock" global-unlock) :int
(typ :unsigned-int))
(cffi:defcfun ("memcpy" memcpy) :int
(dest :unsigned-int)
(src :string)
(coun :unsigned-int))
(defun get-clip-string ()
(open-clip 0)
(let* ((h (get-clip 1)) (s (global-lock-string h)))
(global-unlock h) (close-clip 0) s))
(defun set-clip-string (s)
(let* ((slen (+ 1 (length s)))(newh (global-alloc 8194 slen))
(newp (global-lock newh)))
(memcpy newp s (+ 1 slen)) (global-unlock newh) (open-clip 0)
(set-clip 1 newh) (close-clip 0)))
使用这个json
[HttpPost]
public class TestController : Controller
{
public JsonResult DoJob(dynamic value)
{
//Work with parameter
}
}
更新 这是我从客户端发送请求的方式
{"testObject":{"property":"value"}, "otherPropery": "otherValue"}
答案 0 :(得分:1)
我认为,如果你做的话,json结果它等同于字符串
[HttpPost]
public class TestController : Controller
{
public JsonResult DoJob(string value)
{
//Work with parameter
}
}
它应该有用