2014-10-27 104 views
-3

響應字符串值在Java JSON對象但

deneme2="{\"NUKE_USER_NO\":\"1494\",\"WEB_PIN\":\"metin\",\"CARI_NO\":\"2611\",\"FIRMA_ADI\":\"\",\"CARI_UNVANI\":\"LTDSTI\",\"MOD\":\"Müşteri\",\"RENK\":\"'#fbbb5e'\",\"EMAIL\":\"yok\",\"SAHIS_NO\":\"9\",\"ADISOYADI\":\"Metin\",\"YETKILER\":\"UrunListesi, KampanyaList, YeniUrunler, SepetListe, SiparisTakip, BekleyenSiparisler, TaksitBilgi, TaksitliOdeme, CariEkstre, HavaleEftBildir, BankaHesapNumaralari, PcShirbazi, IadeTalep, IadeSonuclari, GarantiSorgulama, ArizaTakip, UyelikBilgilerim, KullaniciList, SevkAdres, CariHareketler, BorcAlacakDurumu, AlisAnalizi, AlisCirolari, BABS, StandartFormlar, ArizaIadeProseduru, SevkiyatProseduru, Organizasyon, Iletisim, SiparisVerme, GuvenliOdeme3D, MailOrderOranlari, KargoTakip, FiyatMod, AnaSayfa, MusteriTemsilcisiniGorsun, Ihaleler, Puanlarim, UyeIsyeri, IadeDegerlendir, IadeSonucDepo\",\"CARI_TIP_NO\":\"6\",\"AKTIF_SEPET\":\"197\",\"KAR_MARJI\":\"0\",\"ODEME_NO\":\"21\",\"DOVIZ_BIRIMI\":\"USD\",\"NAKLIYE_TIP_NO\":\"11\",\"ROLE_ADI\":\"Bayi\"}"; 

Java代碼

public JSONObject stringToJson(String deneme2) 
{ 
    JSONObject json= new JSONObject(); 
    try { 
     json.getString(deneme2); 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    return json; 
} 

,然後錯誤和異常無值。它不會改變字符串值的JSONObject

http://i.stack.imgur.com/roVu5.png

+1

你到底想幹什麼?你做了什麼?你知道嗎? – 2014-10-27 09:26:22

+0

你究竟在做什麼? – Rohit5k2 2014-10-27 09:28:22

+0

什麼是'stringVeri'?我想你應該使用'json.putString()' – 2014-10-27 09:31:12

回答

0

deneme2是字符串值和deneme2是JSON格式書寫。然後我發送deneme2 stringToJson函數,將字符串轉換爲JSON對象bu返回圖像中的空格和null json。

+2

編輯你的問題,而不是發佈答案 – kId 2014-10-27 09:31:13

+0

thnks的意見,我是新用戶 – metin 2014-10-27 09:37:19

1

首先:

JSONObject json= new JSONObject(); 

沒有采取實際的串需要進行轉換。

public JSONObject stringToJson(String deneme2) 
{ 
    JSONObject json= new JSONObject(deneme2); //pass a String here 
    try { 
     json.getString("key name"); //key for which you need to retrieve data 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 
    return json; 
} 

希望它有幫助。

+0

thnx諮詢它正在運行:) – metin 2014-10-27 09:36:45

+0

偉大,快樂的編碼。接受答案,如果解決。 :) – 2014-10-27 09:37:26

0

試試這個它會幫助你:一是上面的字符串轉換成JSON對象

JSONObject jsonobject = new JSONObject(deneme2); 
try { 
     String abc = json.getString("NUKE_USER_NO");  
     Log.i("Log", abc); 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    }