How to create json using textviews? android studio
i want to create a json like this:
{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}
from my textviews
name = txtName.getText().toString;
id = txtId.getText().toString;
etc
but i do not know how, neither know how the {} are added to json
can someone explain me or tell me an how to create it? thanks
java json android-studio
|
show 3 more comments
i want to create a json like this:
{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}
from my textviews
name = txtName.getText().toString;
id = txtId.getText().toString;
etc
but i do not know how, neither know how the {} are added to json
can someone explain me or tell me an how to create it? thanks
java json android-studio
UseJSONObject
s andJSONArray
s. Here is a tutorial.
– Kartik
Nov 22 '18 at 4:39
Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 22 '18 at 4:40
@Andreas thank you! nothing yet, I'm a little bit confused
– hernyval
Nov 22 '18 at 4:47
@Kartik I will check it, thanks!
– hernyval
Nov 22 '18 at 4:47
Please update once you have tried something. I would suggest to do more Google search first, when you are stuck
– Andreas
Nov 22 '18 at 4:48
|
show 3 more comments
i want to create a json like this:
{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}
from my textviews
name = txtName.getText().toString;
id = txtId.getText().toString;
etc
but i do not know how, neither know how the {} are added to json
can someone explain me or tell me an how to create it? thanks
java json android-studio
i want to create a json like this:
{
"blogs":{
"blog":{
"id":"","name":"","date":"","cant_post":0
},
"detailblog":[{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
},
{
"id":"","name":"","date":0,"cant_post":0,
"creator":0,"theme":0
}]
}
}
from my textviews
name = txtName.getText().toString;
id = txtId.getText().toString;
etc
but i do not know how, neither know how the {} are added to json
can someone explain me or tell me an how to create it? thanks
java json android-studio
java json android-studio
edited Nov 22 '18 at 5:52
hernyval
asked Nov 22 '18 at 4:32
hernyvalhernyval
135
135
UseJSONObject
s andJSONArray
s. Here is a tutorial.
– Kartik
Nov 22 '18 at 4:39
Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 22 '18 at 4:40
@Andreas thank you! nothing yet, I'm a little bit confused
– hernyval
Nov 22 '18 at 4:47
@Kartik I will check it, thanks!
– hernyval
Nov 22 '18 at 4:47
Please update once you have tried something. I would suggest to do more Google search first, when you are stuck
– Andreas
Nov 22 '18 at 4:48
|
show 3 more comments
UseJSONObject
s andJSONArray
s. Here is a tutorial.
– Kartik
Nov 22 '18 at 4:39
Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 22 '18 at 4:40
@Andreas thank you! nothing yet, I'm a little bit confused
– hernyval
Nov 22 '18 at 4:47
@Kartik I will check it, thanks!
– hernyval
Nov 22 '18 at 4:47
Please update once you have tried something. I would suggest to do more Google search first, when you are stuck
– Andreas
Nov 22 '18 at 4:48
Use
JSONObject
s and JSONArray
s. Here is a tutorial.– Kartik
Nov 22 '18 at 4:39
Use
JSONObject
s and JSONArray
s. Here is a tutorial.– Kartik
Nov 22 '18 at 4:39
Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 22 '18 at 4:40
Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 22 '18 at 4:40
@Andreas thank you! nothing yet, I'm a little bit confused
– hernyval
Nov 22 '18 at 4:47
@Andreas thank you! nothing yet, I'm a little bit confused
– hernyval
Nov 22 '18 at 4:47
@Kartik I will check it, thanks!
– hernyval
Nov 22 '18 at 4:47
@Kartik I will check it, thanks!
– hernyval
Nov 22 '18 at 4:47
Please update once you have tried something. I would suggest to do more Google search first, when you are stuck
– Andreas
Nov 22 '18 at 4:48
Please update once you have tried something. I would suggest to do more Google search first, when you are stuck
– Andreas
Nov 22 '18 at 4:48
|
show 3 more comments
1 Answer
1
active
oldest
votes
Let's solve via a bottom up approach
1.create detailblog
array
JSONObject detailblog1 = new JSONObject();
try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog2 = new JSONObject();
try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog3 = new JSONObject();
try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);
2.complete the blog
JSONObject
JSONObject blogs= new JSONObject();
try {
blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
3.complete the blogs
JSONObject
JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("json",json.toString());
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
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%2f53423934%2fhow-to-create-json-using-textviews-android-studio%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Let's solve via a bottom up approach
1.create detailblog
array
JSONObject detailblog1 = new JSONObject();
try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog2 = new JSONObject();
try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog3 = new JSONObject();
try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);
2.complete the blog
JSONObject
JSONObject blogs= new JSONObject();
try {
blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
3.complete the blogs
JSONObject
JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("json",json.toString());
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
add a comment |
Let's solve via a bottom up approach
1.create detailblog
array
JSONObject detailblog1 = new JSONObject();
try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog2 = new JSONObject();
try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog3 = new JSONObject();
try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);
2.complete the blog
JSONObject
JSONObject blogs= new JSONObject();
try {
blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
3.complete the blogs
JSONObject
JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("json",json.toString());
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
add a comment |
Let's solve via a bottom up approach
1.create detailblog
array
JSONObject detailblog1 = new JSONObject();
try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog2 = new JSONObject();
try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog3 = new JSONObject();
try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);
2.complete the blog
JSONObject
JSONObject blogs= new JSONObject();
try {
blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
3.complete the blogs
JSONObject
JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("json",json.toString());
Let's solve via a bottom up approach
1.create detailblog
array
JSONObject detailblog1 = new JSONObject();
try {
detailblog1.put("id","");
detailblog1.put("name","");
detailblog1.put("date",0);
detailblog1.put("cant_post",0);
detailblog1.put("creator",0);
detailblog1.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog2 = new JSONObject();
try {
detailblog2.put("id","");
detailblog2.put("name","");
detailblog2.put("date",0);
detailblog2.put("cant_post",0);
detailblog2.put("creator",0);
detailblog2.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONObject detailblog3 = new JSONObject();
try {
detailblog3.put("id","");
detailblog3.put("name","");
detailblog3.put("date",0);
detailblog3.put("cant_post",0);
detailblog3.put("creator",0);
detailblog3.put("theme",0);
} catch (JSONException e) {
e.printStackTrace();
}
JSONArray jsonArray = new JSONArray();
jsonArray.put(detailblog1);
jsonArray.put(detailblog2);
jsonArray.put(detailblog3);
2.complete the blog
JSONObject
JSONObject blogs= new JSONObject();
try {
blogs.put("blog",blog);
blogs.put("detailblog",jsonArray);
} catch (JSONException e) {
e.printStackTrace();
}
3.complete the blogs
JSONObject
JSONObject json = new JSONObject();
try {
json.put("blogs",blogs);
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("json",json.toString());
edited Nov 23 '18 at 2:01
answered Nov 22 '18 at 12:20
Touhidul IslamTouhidul Islam
1,1841415
1,1841415
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
add a comment |
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
Thanks! Just a question, in json object . blogs . it is: blogs.put("blog", blogs); blogs.put("detailblog", jsonArray); right?
– hernyval
Nov 22 '18 at 20:34
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
@hernyval nice catch, i missed it :)
– Touhidul Islam
Nov 23 '18 at 2:02
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
dont worry! thank you, works perfect
– hernyval
Nov 23 '18 at 2:09
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%2f53423934%2fhow-to-create-json-using-textviews-android-studio%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
Use
JSONObject
s andJSONArray
s. Here is a tutorial.– Kartik
Nov 22 '18 at 4:39
Welcome to StackOverflow! So, what have you tried?
– Andreas
Nov 22 '18 at 4:40
@Andreas thank you! nothing yet, I'm a little bit confused
– hernyval
Nov 22 '18 at 4:47
@Kartik I will check it, thanks!
– hernyval
Nov 22 '18 at 4:47
Please update once you have tried something. I would suggest to do more Google search first, when you are stuck
– Andreas
Nov 22 '18 at 4:48