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

How to create child from Edit Text in Firebase
Firebase get users rank by getting his score in android
Why is there still padding on the left side of my edittext even after removing all padding? [duplicate]
NullPointerException on TextInputLayout.passwordVisibilityToggleRequested
Why does a BroadcastReceiver work without an instance?
Cloud Storage for Android
How to display records from a Firebase database using a condition with Android?
How to programmatically add fragments in a loop to a single activity?
Adding RadioButton in ExpandableListView to RadioGroup
How to check if file is in downloadmanager queue?
Android - Way to pass data without intent
Android GridView wrap column width to content
Force call to ViewPager instantiateItem
TextInput Layout not show floating text
Can't delete ScrollView
RxJava Operator that takes a sample out of multiple events in a certain time frame

Categories

HOME
azure-stream-analytics
microsoftgraph
gdb
c++11
apache-jena
solaris
google-cloud-functions
big-o
ado.net
babeljs
interpolation
project
intercom
dynatrace
gource
enterprise-architect
docx
mongodb-csharp
google-data-studio
wolframalpha
soci
symfony-console
guzzle
href
php-mysqlidb
interpreter
strongname
jboss6.x
mount
tiki-wiki
google-cloud-print
motion-detection
ms-access-2003
entity-relationship-model
user-defined-functions
browser-sync
dotspatial
sql-delete
imx6
openproject
lint
zoomify
outputcache
geotiff
openblas
spring-data-couchbase
ngmaterial
skin
type-theory
mouseleave
monkey
meteor-packages
x-tag
cda
sklearn-pandas
createprocess
invoke-sqlcmd
toast
maybe
boomerang
toran-proxy
decimalformat
dllimport
sony-lifelog-api
mirror
broadband
angular-gettext
ignite-ui
parallel-testing
ray
dct
buffering
android-framework
amslidemenu
notorm
cmmi
robotlegs
nokia-s40
fragmenttransaction
sentestingkit
vfs
xcode3.2
saleslogix
paginator
fusefabric
isa-swizzling
cgimage
listactivity
webdev.webserver
timthumb
twitterizer
qglwidget
cac
tabpanel
appliance

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