Decode JSON with mochijson2 in Erlang

后端 未结 5 917
灰色年华
灰色年华 2021-02-10 07:28

I have a var that has some JSON data:

A = <<\"{\\\"job\\\": {\\\"id\\\": \\\"1\\\"}}\">>. 

Using mochijson2, I decode the data:

5条回答
  •  抹茶落季
    2021-02-10 08:02

    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/man/proplists.html

提交回复
热议问题