mochijson2

Erlang : Tuple List into JSON

旧城冷巷雨未停 提交于 2019-12-12 07:57:58
问题 I have a list of tuples which are http headers. I want to convert the list to a JSON object. I try mochijson2 but to no avail. So I have the following : [{'Accept',"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, {'Accept-Charset',"ISO-8859-1,utf-8;q=0.7,*;q=0.7"}, {'Accept-Encoding',"gzip,deflate"}, {'Accept-Language',"en-us,en;q=0.5"}, {'Cache-Control',"max-age=0"}, {'Connection',"close"}, {'Cookie',"uid=CsDbk0y1bKEzLAOzAwZUAg=="}, {'User-Agent',"Mozilla/5.0 (Macintosh; U

Decode JSON with mochijson2 in Erlang

ⅰ亾dé卋堺 提交于 2019-12-04 12:33:19
问题 I have a var that has some JSON data: A = <<"{\"job\": {\"id\": \"1\"}}">>. Using mochijson2, I decode the data: Struct = mochijson2:decode(A). And now I have this: {struct,[{<<"job">>,{struct,[{<<"id">>,<<"1">>}]}}]} I am trying to read (for example), "job" or "id". I tried using struct.get_value but it doesn't seem to work. Any ideas? 回答1: The data is in {struct, proplist()} format, so here's what you do: {struct, JsonData} = Struct, {struct, Job} = proplists:get_value(<<"job">>, JsonData),

Erlang : Tuple List into JSON

孤人 提交于 2019-12-03 12:51:23
I have a list of tuples which are http headers. I want to convert the list to a JSON object. I try mochijson2 but to no avail. So I have the following : [{'Accept',"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}, {'Accept-Charset',"ISO-8859-1,utf-8;q=0.7,*;q=0.7"}, {'Accept-Encoding',"gzip,deflate"}, {'Accept-Language',"en-us,en;q=0.5"}, {'Cache-Control',"max-age=0"}, {'Connection',"close"}, {'Cookie',"uid=CsDbk0y1bKEzLAOzAwZUAg=="}, {'User-Agent',"Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"}] And would like this ( a

Decode JSON with mochijson2 in Erlang

不问归期 提交于 2019-12-03 08:16:10
I have a var that has some JSON data: A = <<"{\"job\": {\"id\": \"1\"}}">>. Using mochijson2, I decode the data: Struct = mochijson2:decode(A). And now I have this: {struct,[{<<"job">>,{struct,[{<<"id">>,<<"1">>}]}}]} I am trying to read (for example), "job" or "id". I tried using struct.get_value but it doesn't seem to work. Any ideas? The data is in {struct, proplist()} format, so here's what you do: {struct, JsonData} = Struct, {struct, Job} = proplists:get_value(<<"job">>, JsonData), Id = proplists:get_value(<<"id">>, Job), You can read more about proplists at: http://www.erlang.org/doc