java中JSON对象的字符串值,但没有值

时间:2014-10-27 09:22:24

标签: java android 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

3 个答案:

答案 0 :(得分: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;
}

希望它有所帮助。

答案 1 :(得分:0)

deneme 2是字符串值,deneme 2是JSON写入格式。然后我发送了deneme2 stringToJson函数,用于将字符串转换为JSON对象,返回图像中的return except和null json。

答案 2 :(得分:0)

试试这个它会对你有所帮助:首先将上面的String转换为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();
    }