How to parse null name json array(only strings)
I tried to parse this JSON address but failed. The code I tried is failing, no data is reflected. Can you help me?
My Code;
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(null);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject hit = jsonArray.getJSONObject(i);
String imageref = hit.getString(null);
mExampleList.add(new ExampleItemRef(imageref));
}
This JSON;
[
"https://www.asdasd.com/images/r/a.png",
"https://www.asdasd.com/images/r/b.png",
"https://www.asdasd.com/images/r/c.png",
"https://www.asdasd.com/images/r/d.png",
"https://www.asdasd.com/images/r/e.png"
]
android arrays json parsing
add a comment |
I tried to parse this JSON address but failed. The code I tried is failing, no data is reflected. Can you help me?
My Code;
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(null);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject hit = jsonArray.getJSONObject(i);
String imageref = hit.getString(null);
mExampleList.add(new ExampleItemRef(imageref));
}
This JSON;
[
"https://www.asdasd.com/images/r/a.png",
"https://www.asdasd.com/images/r/b.png",
"https://www.asdasd.com/images/r/c.png",
"https://www.asdasd.com/images/r/d.png",
"https://www.asdasd.com/images/r/e.png"
]
android arrays json parsing
From the code you provided, it looks like you're iterating through a new JSON array that you created (new JSONArray()
creates an empty JSON array object), which means it will contain no elements. You should be obtaining the array containing the strings. Without knowing the source of your JSON (e.g. service response, programmatically created object, JSON string?), it is hard to provide a complete answer. If the source is simply a JSON string, you can check out this answer: stackoverflow.com/questions/18977144/…
– Vinnie
Nov 18 '18 at 3:08
empty json do not return my code as follows: JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:41
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
add a comment |
I tried to parse this JSON address but failed. The code I tried is failing, no data is reflected. Can you help me?
My Code;
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(null);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject hit = jsonArray.getJSONObject(i);
String imageref = hit.getString(null);
mExampleList.add(new ExampleItemRef(imageref));
}
This JSON;
[
"https://www.asdasd.com/images/r/a.png",
"https://www.asdasd.com/images/r/b.png",
"https://www.asdasd.com/images/r/c.png",
"https://www.asdasd.com/images/r/d.png",
"https://www.asdasd.com/images/r/e.png"
]
android arrays json parsing
I tried to parse this JSON address but failed. The code I tried is failing, no data is reflected. Can you help me?
My Code;
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(null);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject hit = jsonArray.getJSONObject(i);
String imageref = hit.getString(null);
mExampleList.add(new ExampleItemRef(imageref));
}
This JSON;
[
"https://www.asdasd.com/images/r/a.png",
"https://www.asdasd.com/images/r/b.png",
"https://www.asdasd.com/images/r/c.png",
"https://www.asdasd.com/images/r/d.png",
"https://www.asdasd.com/images/r/e.png"
]
[
"https://www.asdasd.com/images/r/a.png",
"https://www.asdasd.com/images/r/b.png",
"https://www.asdasd.com/images/r/c.png",
"https://www.asdasd.com/images/r/d.png",
"https://www.asdasd.com/images/r/e.png"
]
[
"https://www.asdasd.com/images/r/a.png",
"https://www.asdasd.com/images/r/b.png",
"https://www.asdasd.com/images/r/c.png",
"https://www.asdasd.com/images/r/d.png",
"https://www.asdasd.com/images/r/e.png"
]
android arrays json parsing
android arrays json parsing
edited Nov 18 '18 at 3:45
user10669131
asked Nov 18 '18 at 2:51
user10669131user10669131
11
11
From the code you provided, it looks like you're iterating through a new JSON array that you created (new JSONArray()
creates an empty JSON array object), which means it will contain no elements. You should be obtaining the array containing the strings. Without knowing the source of your JSON (e.g. service response, programmatically created object, JSON string?), it is hard to provide a complete answer. If the source is simply a JSON string, you can check out this answer: stackoverflow.com/questions/18977144/…
– Vinnie
Nov 18 '18 at 3:08
empty json do not return my code as follows: JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:41
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
add a comment |
From the code you provided, it looks like you're iterating through a new JSON array that you created (new JSONArray()
creates an empty JSON array object), which means it will contain no elements. You should be obtaining the array containing the strings. Without knowing the source of your JSON (e.g. service response, programmatically created object, JSON string?), it is hard to provide a complete answer. If the source is simply a JSON string, you can check out this answer: stackoverflow.com/questions/18977144/…
– Vinnie
Nov 18 '18 at 3:08
empty json do not return my code as follows: JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:41
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
From the code you provided, it looks like you're iterating through a new JSON array that you created (
new JSONArray()
creates an empty JSON array object), which means it will contain no elements. You should be obtaining the array containing the strings. Without knowing the source of your JSON (e.g. service response, programmatically created object, JSON string?), it is hard to provide a complete answer. If the source is simply a JSON string, you can check out this answer: stackoverflow.com/questions/18977144/…– Vinnie
Nov 18 '18 at 3:08
From the code you provided, it looks like you're iterating through a new JSON array that you created (
new JSONArray()
creates an empty JSON array object), which means it will contain no elements. You should be obtaining the array containing the strings. Without knowing the source of your JSON (e.g. service response, programmatically created object, JSON string?), it is hard to provide a complete answer. If the source is simply a JSON string, you can check out this answer: stackoverflow.com/questions/18977144/…– Vinnie
Nov 18 '18 at 3:08
empty json do not return my code as follows: JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:41
empty json do not return my code as follows: JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:41
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
add a comment |
2 Answers
2
active
oldest
votes
Just remove all unnecessary part from your code and change it like below. You need to put your json string when creating array
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
mExampleList.add(new ExampleItemRef(jsonArray.getString(i)));
}
}
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
add a comment |
You could do like this:
ArrayList < ExampleItemRef > mExampleList = new ArrayList <ExampleItemRef > ();
String jsonStr =
"[ "https://www.asdasd.com/images/r/a.png", "https://www.asdasd.com/images/r/b.png", "https://www.asdasd.com/images/r/c.png", "https://www.asdasd.com/images/r/d.png", "https://www.asdasd.com/images/r/e.png" ]";
try {
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
} catch (JSONException e) {
e.printStackTrace();
}
codes are self explanatory, so no comments,hope helpful
Edited: try this:
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = new JSONArray(response.toString());
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357468%2fhow-to-parse-null-name-json-arrayonly-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Just remove all unnecessary part from your code and change it like below. You need to put your json string when creating array
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
mExampleList.add(new ExampleItemRef(jsonArray.getString(i)));
}
}
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
add a comment |
Just remove all unnecessary part from your code and change it like below. You need to put your json string when creating array
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
mExampleList.add(new ExampleItemRef(jsonArray.getString(i)));
}
}
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
add a comment |
Just remove all unnecessary part from your code and change it like below. You need to put your json string when creating array
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
mExampleList.add(new ExampleItemRef(jsonArray.getString(i)));
}
}
Just remove all unnecessary part from your code and change it like below. You need to put your json string when creating array
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray(jsonString);
for (int i = 0; i < jsonArray.length(); i++) {
mExampleList.add(new ExampleItemRef(jsonArray.getString(i)));
}
}
edited Nov 18 '18 at 4:00
answered Nov 18 '18 at 3:04
LuceferLucefer
1,1211511
1,1211511
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
add a comment |
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
I updated answer @user10669131 just try
– Lucefer
Nov 18 '18 at 3:53
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
"jsonString" will be ur JSON Array without keys. Try it as empty string ""
– Lucefer
Nov 18 '18 at 4:02
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:32
add a comment |
You could do like this:
ArrayList < ExampleItemRef > mExampleList = new ArrayList <ExampleItemRef > ();
String jsonStr =
"[ "https://www.asdasd.com/images/r/a.png", "https://www.asdasd.com/images/r/b.png", "https://www.asdasd.com/images/r/c.png", "https://www.asdasd.com/images/r/d.png", "https://www.asdasd.com/images/r/e.png" ]";
try {
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
} catch (JSONException e) {
e.printStackTrace();
}
codes are self explanatory, so no comments,hope helpful
Edited: try this:
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = new JSONArray(response.toString());
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
add a comment |
You could do like this:
ArrayList < ExampleItemRef > mExampleList = new ArrayList <ExampleItemRef > ();
String jsonStr =
"[ "https://www.asdasd.com/images/r/a.png", "https://www.asdasd.com/images/r/b.png", "https://www.asdasd.com/images/r/c.png", "https://www.asdasd.com/images/r/d.png", "https://www.asdasd.com/images/r/e.png" ]";
try {
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
} catch (JSONException e) {
e.printStackTrace();
}
codes are self explanatory, so no comments,hope helpful
Edited: try this:
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = new JSONArray(response.toString());
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
add a comment |
You could do like this:
ArrayList < ExampleItemRef > mExampleList = new ArrayList <ExampleItemRef > ();
String jsonStr =
"[ "https://www.asdasd.com/images/r/a.png", "https://www.asdasd.com/images/r/b.png", "https://www.asdasd.com/images/r/c.png", "https://www.asdasd.com/images/r/d.png", "https://www.asdasd.com/images/r/e.png" ]";
try {
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
} catch (JSONException e) {
e.printStackTrace();
}
codes are self explanatory, so no comments,hope helpful
Edited: try this:
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = new JSONArray(response.toString());
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
You could do like this:
ArrayList < ExampleItemRef > mExampleList = new ArrayList <ExampleItemRef > ();
String jsonStr =
"[ "https://www.asdasd.com/images/r/a.png", "https://www.asdasd.com/images/r/b.png", "https://www.asdasd.com/images/r/c.png", "https://www.asdasd.com/images/r/d.png", "https://www.asdasd.com/images/r/e.png" ]";
try {
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
} catch (JSONException e) {
e.printStackTrace();
}
codes are self explanatory, so no comments,hope helpful
Edited: try this:
private void parseJSON() {
final String url = "json website";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = new JSONArray(response.toString());
for (int i = 0; i < jsonArray.length(); i++) {
String imageref = jsonArray.getString(i);
mExampleList.add(new ExampleItemRef(imageref));
}
edited Nov 18 '18 at 4:18
answered Nov 18 '18 at 3:21
navylovernavylover
3,42021118
3,42021118
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
add a comment |
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
hey, thenks but my json not string. in this way; final String url = "JSON WEBSITE"; JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) { try { JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:42
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
@user10669131 see my edited
– navylover
Nov 18 '18 at 4:23
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
Unfortunately, it didn't work
– user10669131
Nov 18 '18 at 13:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53357468%2fhow-to-parse-null-name-json-arrayonly-strings%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
From the code you provided, it looks like you're iterating through a new JSON array that you created (
new JSONArray()
creates an empty JSON array object), which means it will contain no elements. You should be obtaining the array containing the strings. Without knowing the source of your JSON (e.g. service response, programmatically created object, JSON string?), it is hard to provide a complete answer. If the source is simply a JSON string, you can check out this answer: stackoverflow.com/questions/18977144/…– Vinnie
Nov 18 '18 at 3:08
empty json do not return my code as follows: JSONArray jsonArray = response.getJSONArray(null);
– user10669131
Nov 18 '18 at 3:41
I edited the message, can you see?
– user10669131
Nov 18 '18 at 3:45