SORU
14 Mayıs 2012, PAZARTESİ


Android Json ve boş değerler

Nasıl bir json değeri null olduğunda algılayabilir miyim? örneğin:[{"": null} kullanıcı adı {"":""} null] . username

İlk vaka unexisting bir kullanıcı adı ve bir kullanıcı adında ikinci temsil eder"". null Ama eğer onları almaya çalışırsanız hem değerleri dize neden"" . null

JSONObject json = new JSONObject("{\"hello\":null}");
json.put("bye", JSONObject.NULL);
Log.e("LOG", json.toString());
Log.e("LOG", "hello=" json.getString("hello")   " is null? "
                  (json.getString("hello") == null));
Log.e("LOG", "bye=" json.getString("bye")   " is null? "
                  (json.getString("bye") == null));

Günlük çıktı

{"hello":"null","bye":null}
hello=null is null? false
bye=null is null? false

CEVAP
14 Mayıs 2012, PAZARTESİ


json.isNull( "field-name" ) ile deneyin.

Referans: http://developer.android.com/reference/org/json/JSONObject.html#isNull(java.lang.String)

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • Bucky Roberts

    Bucky Robert

    9 HAZİRAN 2011
  • kndx

    kndx

    11 Mart 2006
  • PlayStation

    PlayStation

    16 Aralık 2005