- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 Python 模块,其中包含我正在初始化的 Person 对象
person = {
'name': "",
'city': "",
'phone1': "",
'emailaddress': "",
}
然后我尝试填充这些字段,如果我无法获得我想要的值,我会返回到默认的空字符串。然后我发布对象:
req = urllib2.Request('API_LOCATION')
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps(person))
另一方面,我正在使用一个收集人员的 ASP.NET web api,我发现应该为空字符串的项目为 null
[System.Web.Http.HttpPost]
[System.Web.Http.Route("api/postperson")]
public JsonResult PostPerson(Person item)
{
... Items that I expect to be empty strings are actually null
}
我做错了什么?我想在 python 模块中发送空字符串,而不是空值。我已经测试过使用 ASP.NET 客户端发布到相同的 api,并且在该实例中正确地遇到了空字符串。
最佳答案
json
工作正常。只是 urllib
有一个非常困惑、冗长且完全不直观的界面。以下是使用 urllib
提交这些数据参数的方法:
import urllib
import urllib2
data = urllib.urlencode(person)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
但实际上,您应该立即摆脱 urllib
并开始使用 requests
reponse = requests.get(url, data=person)
或
response = requests.post(url, data=person)
关于Python json.dumps 将空字符串转换为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35100532/
我正在尝试创建一个程序,其中字符串的前三个字符重复给定次数,如下所示: foo('Chocolate', 3) # => 'ChoChoCho' foo('Abc', 3) # => 'AbcAbcA
我有以下字符串: std::string str = "Mode:AAA:val:101:id:A1"; 我想分离一个位于 "val:" 和 ":id" 之间的子字符串,这是我的方法: std::st
DNA 字符串可以是任意长度,包含 5 个字母(A、T、G、C、N)的任意组合。 压缩包含 5 个字母(A、T、G、C、N)的 DNA 字母串的有效方法是什么?不是考虑每个字母表 3 位,我们可以使用
是否有一种使用 levenstein 距离将一个特定字符串与第二个较长字符串中的任何区域进行匹配的好方法? 例子: str1='aaaaa' str2='bbbbbbaabaabbbb' if str
使用 OAuth 并使用以下函数使用我们称为“foo”(实际上是 OAuth token )的字符串加密 key public function encrypt( $text ) { // a
我是一名优秀的程序员,十分优秀!