java properties to json

后端 未结 10 1605
情书的邮戳
情书的邮戳 2020-12-13 18:06

Is there an easy way to convert properties with dot notation to json

I.E

server.host=foo.bar
server.port=1234

TO

{
         


        
10条回答
  •  忘掉有多难
    2020-12-13 18:55

    Try reading this http://www.oracle.com/technetwork/articles/java/json-1973242.html, you will find several class to work with json.

    I guess that retrieving the json from a local file, inner resource in the jar, or in another location specificable by an URL and the just read it with a JsonReader get the job dones.


    This is a snipped from the reference site posted before.

     URL url = new URL("https://graph.facebook.com/search?q=java&type=post");
     try (InputStream is = url.openStream();
          JsonReader rdr = Json.createReader(is)) {
    
          JsonObject obj = rdr.readObject();
          // from this line forward you got what you want :D
    
         }
     }
    

    Hope it helps!

提交回复
热议问题