Android Question php and json

tufanv

Expert
Licensed User
Longtime User
hello,

B4X:
$q = "SELECT cihazid,username,cesit,nesne FROM tblusers WHERE cihazid = '".$cihaz."'";
$r = mysql_query($q);
$a = mysql_fetch_assoc($r);if ( mysql_num_rows($r) > 0 )
{
print json_encode("$a['username']);

with this, i can successfuly get the username from db and put it into label1 in my app with retrieved json. I also want to put the other values : cesit,nesne,cihazid into label2,3,4 . Icant put them all into json as single line because later in the app i cant extract them. How can i get them as a map or list for example so i can retrieve the field i like in my app ?

TY
 

tufanv

Expert
Licensed User
Longtime User
yes that takes it. And i want to pull a value by coloumn name for example what i get is :
B4X:
Response from server: {"soru":"Deneme yaparim","cins":"0","s1":"Evet","s2":"Hay\u0131r","s3":"Fikrim Yok","s4":"","onay":"1","public":"0","tarih":"2016-04-04 10:59:52","anketid":"19","publicid":"1247964493","username":"duffann","kategori":"Ya\u015fam"}

If i want to get the coloumn "soru" in my app , i tried :
B4X:
                    Dim parser As JSONParser
                    parser.Initialize(res)
                    Dim m As Map
                    Dim l As List
                    l = parser.Nextarray

so that i can use m.get("soru") but i got error :

Expected: NSArray, object type: B4AMap.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize(<yourjsontext>)
Dim root As Map = parser.NextObject
Dim s3 As String = root.Get("s3")
Dim s4 As String = root.Get("s4")
Dim onay As String = root.Get("onay")
Dim cins As String = root.Get("cins")
Dim soru As String = root.Get("soru")
Dim kategori As String = root.Get("kategori")
Dim anketid As String = root.Get("anketid")
Dim public As String = root.Get("public")
Dim tarih As String = root.Get("tarih")
Dim s1 As String = root.Get("s1")
Dim publicid As String = root.Get("publicid")
Dim s2 As String = root.Get("s2")
Dim username As String = root.Get("username")
 
Upvote 0

tufanv

Expert
Licensed User
Longtime User


Thanks. I tried it. I use:

B4X:
Dim res As String
Dim parser As JSONParser
res = Job.GetString
Log(res)
parser.Initialize(res)
Dim root As Map = parser.NextObject
Log(root.Get("soru"))

here log res gives the json text :
B4X:
{"soru":"Deneme yaparim","cins":"0","s1":"Evet","s2":"Hay\u0131r","s3":"Fikrim Yok","s4":"","onay":"1","public":"0","tarih":"2016-04-04 10:59:52","anketid":"19","publicid":"1247964493","username":"duffann","kategori":"Ya\u015fam"}

but parser.Initialize(res) gives the error:
Target is null. Method called: Get:
 
Last edited:
Upvote 0

tufanv

Expert
Licensed User
Longtime User

It works now. Thanks for your help. I dont know how i fixed it =)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…