Tag: json

getString()和optString()之间的区别

JSON中的getString()和optString()什么区别?

为什么节俭,为什么不使用HTTP RPC(JSON + gzip)

节俭的主要目标是实现跨编程语言的高效可靠的通信。 但我认为HTTP-RPC也可以这样做,web开发人员几乎每个人都知道如何在http上工作,并且比Thrift更容易实现HTTP-RPC(json) 也许Thrift-RPC更快,那么谁能告诉我他们之间的差异?

发送一个JSON到服务器,并返回一个JSON,没有JQuery

我需要发送一个JSON(可以stringify)到服务器,并在用户端检索得到的JSON,而不使用JQuery。 如果我应该使用GET,我如何通过JSON作为参数? 是否有风险太长? 如果我应该使用POST,如何在GET中设置onload函数的等价物? 或者我应该使用不同的方法? 备注 这个问题不是关于发送一个简单的AJAX。 它不应该被重复closures。

从JSON到ruby哈希?

我可以使用一种方式 require 'json' def saveUserLib(user_lib) File.open("/Users/name/Documents/user_lib.json","w") do |f| f.write($user_lib.to_json) end end uname = gets.chomp $user_lib["_uname"] = uname saveUserLib($user_lib) 但是我怎样才能把它作为我的user_lib?

使用Jackson的ObjectMapper的JSON对象的顺序

我使用ObjectMapper来执行我的java-json映射。 ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter(); ow.writeValue(new File( fileName +".json"), jsonObj); 这是我的Java类: public class Relation { private String id; private String source; private String target; private String label; private List<RelAttribute> attributes; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getSource() { return source; } public […]

如何解码JSON的types从string转换为在Golang中的float64?

我需要解码一个JSONstring的浮点数如下: {"name":"Galaxy Nexus", "price":"3460.00"} 我使用下面的Golang代码: package main import ( "encoding/json" "fmt" ) type Product struct { Name string Price float64 } func main() { s := `{"name":"Galaxy Nexus", "price":"3460.00"}` var pro Product err := json.Unmarshal([]byte(s), &pro) if err == nil { fmt.Printf("%+v\n", pro) } else { fmt.Println(err) fmt.Printf("%+v\n", pro) } } 当我运行它时,得到结果: json: cannot unmarshal […]

用逗号分割NSString

我有一个JSON提要连接到我的应用程序。 其中一项是以逗号分隔的lat&long。 例如:“32.0235,1.345”。 我试图用逗号分割成两个单独的值。 有什么build议? 谢谢!!

curl输出在UNIX shell脚本中以可读的JSON格式显示

在我的UNIX shell脚本中,当我执行一个curl命令时,我的curl结果将显示如下,我将它redirect到文件: {"type":"Show","id":"123","title":"name","description":"Funny","channelTitle":"ifood.tv","lastUpdateTimestamp":"2014-04-20T20:34:59","numOfVideos":"15"} 但是,我希望这个输出在文件中像下面一样可读的JSON格式: {"type":"Show", "id":"123", "title":"name", "description":"Funny", "channelTitle":"ifood.tv", "lastUpdateTimestamp":"2014-04-20T20:34:59", "numOfVideos":"15"} 请build议

不能在Ubuntu上安装json gem与ruby 2.2.3

我正在浏览一个Rails教程,由于json gem的问题,我无法完成“bundle install”。 当我尝试直接安装它时: me@tru2:~/rails/hello_app$ gem install json -v '1.8.3' Building native extensions. This could take a while… ERROR: Error installing json: ERROR: Failed to build gem native extension. /home/me/.rvm/rubies/ruby-2.2.3-dev/bin/ruby -r ./siteconf20150820-12793-qdkev7.rb extconf.rb creating Makefile make "DESTDIR=" clean make "DESTDIR=" compiling generator.c linking shared-object json/ext/generator.so /usr/bin/ld: cannot find -lgmp collect2: error: ld returned 1 exit […]

在Golang中解组嵌套的JSON对象

关于这个话题 有 几个 问题 ,但是他们都没有涉及我的案子,因此我正在创build一个新的问题。 我有以下JSON: {"foo":{ "bar": "1", "baz": "2" }, "more": "text"} 有没有一种方法来解组嵌套bar属性,并将其直接分配给一个struct属性而不创build一个嵌套的结构? 我现在采用的解决scheme如下: type Foo struct { More String `json:"more"` Foo struct { Bar string `json:"bar"` Baz string `json:"baz"` } `json:"foo"` // FooBar string `json:"foo.bar"` } 这是一个简化的版本,请忽略冗长。 正如你所看到的,我希望能够parsing和赋值 // FooBar string `json:"foo.bar"` 我见过有人用地图,但那不是我的情况。 我基本上不关心foo (这是一个大对象)的内容,除了一些特定的元素。 在这种情况下,正确的做法是什么? 我不是在寻找怪异的黑客,因此,如果这是要走的路,我很好。