2012-09-09 3 views
0

에 대해 언급 한 json 형식을 생성하는 방법 누군가 다음 코드에서 안드로이드 앱의 GSON Google 라이브러리를 사용하여 내 Json 문자열을 빌드하는 방법에 대한 몇 가지 코드를 알려주십시오.WCF REST API

아래와 같이 JsonStringer를 사용하여 아래에 언급 된 문자열을 생성했습니다.

JSONStringer stringer = new JSONStringer() 
        .object() 
        .key("loginRequest") 
        .object() 
        .key("UserId").value("007") 
        .key("Password").value("125987563") 
        .key("LicenseKey").value("My Project Key") 
        .key("MobileId").value("This is mobile id") 
        .endObject() 
        .endObject(); 

{"loginRequest":{"UserId":"007","Password":"125987563","LicenseKey":"This is License Key","MobileId":"This is mobile id"}} 

Gson을 사용하여 위에서 언급 한 문자열을 어떻게 생성 할 수 있는지 조언하십시오. 그것은 거의 정확히 동일합니다

감사

답변

0

:

final StringWriter sw = new StringWriter(); 
new JsonWriter(sw) 
.beginObject() 
.name("loginRequest") 
.beginObject() 
.name("userId").value("007") 
.name("password").value("123") 
.endObject() 
.endObject() 
.close();