Can i use JSON.Stringify in code-behind of an ASP.Net project
up vote
8
down vote
favorite
In the code-behind of an ASP.NET project (MVP-pattern) I get in one of the presenters a string which contains something which looks like the content of a JSON file.
Then I set one of the properties of the view - which is assigned to the presenter - with that string.
In the view the string is displayed in a TextBox, but it doesn't look good, because it is not structured with newlines and line feeds.
I know there is a JSON-function called Stringify which can make such strings pretty.
Can I call that JSON-function in code-behind?
Per example when I set the property of the view in the presenter?
So I set it in the presenter:
this.view.ContentAsJson = GetContentAsJson(uuid);
This is what I would like to do, if it's possible:
this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
GetContentAsJson
is a function which creates and returns the JSON-string.
This is my view:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
<p>
<asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
</p>
</div>
This is the property in the view which gets the string:
public string ContentAsJson
set
if (!string.IsNullOrEmpty(value))
TbContentJson.Text = value;
else
TbContentJson.Text = "";
c# asp.net json
add a comment |
up vote
8
down vote
favorite
In the code-behind of an ASP.NET project (MVP-pattern) I get in one of the presenters a string which contains something which looks like the content of a JSON file.
Then I set one of the properties of the view - which is assigned to the presenter - with that string.
In the view the string is displayed in a TextBox, but it doesn't look good, because it is not structured with newlines and line feeds.
I know there is a JSON-function called Stringify which can make such strings pretty.
Can I call that JSON-function in code-behind?
Per example when I set the property of the view in the presenter?
So I set it in the presenter:
this.view.ContentAsJson = GetContentAsJson(uuid);
This is what I would like to do, if it's possible:
this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
GetContentAsJson
is a function which creates and returns the JSON-string.
This is my view:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
<p>
<asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
</p>
</div>
This is the property in the view which gets the string:
public string ContentAsJson
set
if (!string.IsNullOrEmpty(value))
TbContentJson.Text = value;
else
TbContentJson.Text = "";
c# asp.net json
just post a snippet of what you have tried ?
– BRAHIM Kamel
Feb 20 '17 at 11:30
Possible duplicate of How can I beautify JSON for display in a TextBox?
– David Culp
Feb 20 '17 at 11:33
Okay, i edited my Explanation and added a few examples from my project.
– Patrick Pirzer
Feb 20 '17 at 11:38
what does GetContentAsJson(uuid) return?
– Sujit.Warrier
Feb 20 '17 at 11:39
No, it's just a string variable for getting data. That data is used for creating the content of the JSON.
– Patrick Pirzer
Feb 20 '17 at 11:40
add a comment |
up vote
8
down vote
favorite
up vote
8
down vote
favorite
In the code-behind of an ASP.NET project (MVP-pattern) I get in one of the presenters a string which contains something which looks like the content of a JSON file.
Then I set one of the properties of the view - which is assigned to the presenter - with that string.
In the view the string is displayed in a TextBox, but it doesn't look good, because it is not structured with newlines and line feeds.
I know there is a JSON-function called Stringify which can make such strings pretty.
Can I call that JSON-function in code-behind?
Per example when I set the property of the view in the presenter?
So I set it in the presenter:
this.view.ContentAsJson = GetContentAsJson(uuid);
This is what I would like to do, if it's possible:
this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
GetContentAsJson
is a function which creates and returns the JSON-string.
This is my view:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
<p>
<asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
</p>
</div>
This is the property in the view which gets the string:
public string ContentAsJson
set
if (!string.IsNullOrEmpty(value))
TbContentJson.Text = value;
else
TbContentJson.Text = "";
c# asp.net json
In the code-behind of an ASP.NET project (MVP-pattern) I get in one of the presenters a string which contains something which looks like the content of a JSON file.
Then I set one of the properties of the view - which is assigned to the presenter - with that string.
In the view the string is displayed in a TextBox, but it doesn't look good, because it is not structured with newlines and line feeds.
I know there is a JSON-function called Stringify which can make such strings pretty.
Can I call that JSON-function in code-behind?
Per example when I set the property of the view in the presenter?
So I set it in the presenter:
this.view.ContentAsJson = GetContentAsJson(uuid);
This is what I would like to do, if it's possible:
this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
GetContentAsJson
is a function which creates and returns the JSON-string.
This is my view:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
<p>
<asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
</p>
</div>
This is the property in the view which gets the string:
public string ContentAsJson
set
if (!string.IsNullOrEmpty(value))
TbContentJson.Text = value;
else
TbContentJson.Text = "";
c# asp.net json
c# asp.net json
edited Feb 20 '17 at 13:05
user3378165
2,23762456
2,23762456
asked Feb 20 '17 at 11:27
Patrick Pirzer
7171824
7171824
just post a snippet of what you have tried ?
– BRAHIM Kamel
Feb 20 '17 at 11:30
Possible duplicate of How can I beautify JSON for display in a TextBox?
– David Culp
Feb 20 '17 at 11:33
Okay, i edited my Explanation and added a few examples from my project.
– Patrick Pirzer
Feb 20 '17 at 11:38
what does GetContentAsJson(uuid) return?
– Sujit.Warrier
Feb 20 '17 at 11:39
No, it's just a string variable for getting data. That data is used for creating the content of the JSON.
– Patrick Pirzer
Feb 20 '17 at 11:40
add a comment |
just post a snippet of what you have tried ?
– BRAHIM Kamel
Feb 20 '17 at 11:30
Possible duplicate of How can I beautify JSON for display in a TextBox?
– David Culp
Feb 20 '17 at 11:33
Okay, i edited my Explanation and added a few examples from my project.
– Patrick Pirzer
Feb 20 '17 at 11:38
what does GetContentAsJson(uuid) return?
– Sujit.Warrier
Feb 20 '17 at 11:39
No, it's just a string variable for getting data. That data is used for creating the content of the JSON.
– Patrick Pirzer
Feb 20 '17 at 11:40
just post a snippet of what you have tried ?
– BRAHIM Kamel
Feb 20 '17 at 11:30
just post a snippet of what you have tried ?
– BRAHIM Kamel
Feb 20 '17 at 11:30
Possible duplicate of How can I beautify JSON for display in a TextBox?
– David Culp
Feb 20 '17 at 11:33
Possible duplicate of How can I beautify JSON for display in a TextBox?
– David Culp
Feb 20 '17 at 11:33
Okay, i edited my Explanation and added a few examples from my project.
– Patrick Pirzer
Feb 20 '17 at 11:38
Okay, i edited my Explanation and added a few examples from my project.
– Patrick Pirzer
Feb 20 '17 at 11:38
what does GetContentAsJson(uuid) return?
– Sujit.Warrier
Feb 20 '17 at 11:39
what does GetContentAsJson(uuid) return?
– Sujit.Warrier
Feb 20 '17 at 11:39
No, it's just a string variable for getting data. That data is used for creating the content of the JSON.
– Patrick Pirzer
Feb 20 '17 at 11:40
No, it's just a string variable for getting data. That data is used for creating the content of the JSON.
– Patrick Pirzer
Feb 20 '17 at 11:40
add a comment |
2 Answers
2
active
oldest
votes
up vote
16
down vote
accepted
JSON.stringify()
Actually Converts a JavaScript object into a string, you can do it in server side like this:
using System.Web.Script.Serialization;
var json = new JavaScriptSerializer().Serialize(obj);
Edit: JSON.stringify()
is a client side(browser) functionality. So you can't do that on the server side.
add a comment |
up vote
0
down vote
You can use something like
JsonConvert.SerializeObject(ob)
From library: Newtonsoft.Json
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
16
down vote
accepted
JSON.stringify()
Actually Converts a JavaScript object into a string, you can do it in server side like this:
using System.Web.Script.Serialization;
var json = new JavaScriptSerializer().Serialize(obj);
Edit: JSON.stringify()
is a client side(browser) functionality. So you can't do that on the server side.
add a comment |
up vote
16
down vote
accepted
JSON.stringify()
Actually Converts a JavaScript object into a string, you can do it in server side like this:
using System.Web.Script.Serialization;
var json = new JavaScriptSerializer().Serialize(obj);
Edit: JSON.stringify()
is a client side(browser) functionality. So you can't do that on the server side.
add a comment |
up vote
16
down vote
accepted
up vote
16
down vote
accepted
JSON.stringify()
Actually Converts a JavaScript object into a string, you can do it in server side like this:
using System.Web.Script.Serialization;
var json = new JavaScriptSerializer().Serialize(obj);
Edit: JSON.stringify()
is a client side(browser) functionality. So you can't do that on the server side.
JSON.stringify()
Actually Converts a JavaScript object into a string, you can do it in server side like this:
using System.Web.Script.Serialization;
var json = new JavaScriptSerializer().Serialize(obj);
Edit: JSON.stringify()
is a client side(browser) functionality. So you can't do that on the server side.
edited Feb 20 '17 at 11:41
radu florescu
3,25484983
3,25484983
answered Feb 20 '17 at 11:33
user3378165
2,23762456
2,23762456
add a comment |
add a comment |
up vote
0
down vote
You can use something like
JsonConvert.SerializeObject(ob)
From library: Newtonsoft.Json
add a comment |
up vote
0
down vote
You can use something like
JsonConvert.SerializeObject(ob)
From library: Newtonsoft.Json
add a comment |
up vote
0
down vote
up vote
0
down vote
You can use something like
JsonConvert.SerializeObject(ob)
From library: Newtonsoft.Json
You can use something like
JsonConvert.SerializeObject(ob)
From library: Newtonsoft.Json
answered Nov 11 at 20:18
DaniCode
19028
19028
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f42343342%2fcan-i-use-json-stringify-in-code-behind-of-an-asp-net-project%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
just post a snippet of what you have tried ?
– BRAHIM Kamel
Feb 20 '17 at 11:30
Possible duplicate of How can I beautify JSON for display in a TextBox?
– David Culp
Feb 20 '17 at 11:33
Okay, i edited my Explanation and added a few examples from my project.
– Patrick Pirzer
Feb 20 '17 at 11:38
what does GetContentAsJson(uuid) return?
– Sujit.Warrier
Feb 20 '17 at 11:39
No, it's just a string variable for getting data. That data is used for creating the content of the JSON.
– Patrick Pirzer
Feb 20 '17 at 11:40