android


Seperating Json array received from php - Android


I have a json function that gathers comments from a database. All the comments are gathered in a php array and sent back to the phone and turned into a jsonobject. Here is my json code
JSONObject json2 = CollectComments.collectComments(usernameforcomments, offsetNumber);
return json2;
When it returns it the json looks like this
{
"tag": "collectComments",
"success": 1,
"error": 0,
"numberOfComments": 16,
"offsetNumber": 1,
"comment": [
"test 16",
"test 15",
"test 14",
"test 13",
"test 12",
"test 11",
"test 10",
"test 9",
"test 8",
"test 7",
"test 6",
"test 5",
"test 4",
"test 3",
"test 2",
"test 1"
]
}
How can I separate all the comments and place them inside their own textview? The comment variable is classified as a string in the beginning of the Activity like this,
private static String KEY_COMMENT = "comment";
Should this be set to array? If so then how can I put each comment into their own textView?
Use need to use getJSONArray("comment"); on the object.
You can then loop through each of the array items.
JSONObject test = new JSONObject("...");
JSONArray array = test.getJSONArray(KEY_COMMENT);
for(int i = 0; i < array.length(); i++) {
textView[i].setText(array.getString(i));
}

Related Links

Display dialogfragment inside Fragment occupying a portion of the screen?
repackage dependancies by proguard to avoid dependency conflicts in gradle
How to deploy multi-module of gradle androidAPP in android studio?
Reduce the textSize of some elements in the navigation drawer
Android installing apk without Known Sources verification?
Couchbase Key Replication
strange issue with scroll up in android gridView
How can i change ImageView's picture from other Activity?
How to solve java.lang.OutOfMemoryError while loading the activity
How to use tmdp api to rate a movie in native android app ..?
Android RecyclerView Adapter Item count is returning 0 on unit testing
Android - Destroy and recreate YoutubePlayerFragment
com.android.dex.DexException: Multiple dex files define LSevenZip/CRC
Android SSLPinning except for one URL
Including C in Android: CFAbsoluteTime, CFGregorianDate, etc
FileOutputStream blocking thread on Android

Categories

HOME
developer-tools
yahoo-finance
sh
spring-data-redis
replace
google-apps
regular-language
angularfire2
octave
google-chrome-app
dynatrace
gource
bitnami
gruntfile
modbus-tcp
bourbon
object-storage
resourcebundle
tiki-wiki
google-cloud-print
fable-f#
bulletphysics
android-maps
errbot
user-defined-functions
volatile
anki
left-join
kodi
android-sugarorm
login-script
vue-chartjs
sql-delete
wurfl
google-earth-engine
filesystemwatcher
linq-to-objects
demo
chef-solo
news
apriori
stylecop
strftime
rfc3339
facebook-social-plugins
colorbar
git-flow
check-mk
google-photos
structuremap4
android-instrumentation
vcloud-director-rest-api
taocp
node-request
hadoop-2.7.2
adafruit
flex4.6
watch-os-2
appscale
atan2
state-restoration
custom-errors
terracotta
dock
branch-and-bound
nutiteq
entity-framework-4.3
public-html
cryptographichashfunction
webmatrix-3
rmysql
xml-namespaces
grails-domain-class
mutual-authentication
eclipse-kepler
artemis
poker
pclzip
resource-management
wimax
usertype
cross-database
google-maps-mobile
filemerge
update-statement
pylucene
timthumb
cdonts
burndowncharts
mathematical-typesetting
netbeans6.1

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App