js
[Gson / JsonObject] json.addProperty 값 출력
natrue
2022. 2. 16. 11:51
728x90
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<!-- json 변환 -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
JsonObject json = new JsonObject();
json.addProperty("url", "/fileupload/"+savedFileName);
json.addProperty("responseCode", "success");
json["url"] 이런식으로 값을 출력 할 수 있다.
success : function(data) {
var json = JSON.parse(data);
console.log("json" + json);
console.log("json[url]" + json["url"]);
console.log("json[responseCode]" + json["responseCode"]);
},
error : function(e) {
console.log(e);
}
결과 출력
json[object Object]
json[url]/fileupload/7e3ab3d4-b71b-4d59-9bba-a03c22e7824b.png
json[responseCode]success