A step-by-step guide on converting JSON data from JavaScript to C# variables

Hey there! I have a JavaScript snippet where I am sending an array to my C# file in JSON format.

var r=['maths','computer','physics']

$.post("Global.aspx", { opt: "postpost", post: w.val(),tags:JSON.stringify(r)
}, function (d) {
});

However, in C#, I am receiving a string like this:

["Maths""Computer""Physics"]

I only want the words 'maths', 'computer', and 'physics' without the brackets and quotation marks. Can you please help me out?

Here is my C# code:

string[] _tags = Request.Form["tags"].ToString().Split(',');
                    string asd="";
                    foreach (string ad in _tags) {
                        asd += ad;

                    }

Answer №1

If you're seeking information on JSON parsing:

One way to achieve this is by using the JavaScriptSerializer class to deserialize a List<string> from the Request.Form["tags"] value.

After splitting your string on the comma character, you end up with an array of:

[0] = "[\"Maths\""
[1] = "\"Computer\""
[2] = "\"Physics\"]"

Keep in mind that square brackets are significant in JSON data and should be handled accordingly for proper processing.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Concealing a block from top to bottom

I currently have a filter that is hidden when clicked, with a transition effect that moves it from the bottom to the top. I have recorded my screen to demonstrate this behavior: . However, I now need the filter to hide from top to bottom instead, essenti ...

What could be causing the vue-property-decorator @Emit to malfunction in my Vue TypeScript file?

I am currently working with Typescript and Vuejs, where I have a child component called child.component.tsx import Vue from 'vue'; import Component from 'vue-class-component'; import { Emit } from 'vue-property-decorator'; ...

Ensure the smooth scrolling feature is activated by adding an active class when either clicking or manually scrolling the

I have a script that enables smooth page scrolling, but I want it to automatically add an "active" class to the link corresponding to the section currently in view. While there are similar solutions out there, most of them only apply the class when the lin ...

Troubleshooting: Unable to Sort Column in ngx-DataTable Angular 4

As a newcomer to Angular, I have been encountering some challenges while using ngx-DataTable. I am currently utilizing a simple ngx-DataTable for basic operations. The issue I am facing is that the sorting functionality is not working on a specific column, ...

"Step-by-Step Guide: Implementing a Modal Popup Form in Angular with NgBootstrap and FormsModule

I am seeking assistance with my Angular project. I am attempting to implement a Modal Popup Form using NgBootstrap and FormsModule, but encountering issues with the NgbModule not being imported. Here are some details of my setup: node 16.15.1 cli 15.1.5 co ...

Step-by-step guide to implementing a datepicker textfield with Vuetify 3

I'm currently exploring Vuetify 3 and aiming to implement a textfield that serves as a datepicker. For reference, you can find a similar example in the Vuetify 2 documentation here. Unfortunately, the Vuetify 3 docs do not yet include an example like ...

Use Picasso to loop through and display images within an image set

Here is a sample of my .json file: { "0": { "image_path": "192.168.1.52/test/image/im1.jpg", "title": "image 1" }, "1": { "image_path": "192.168.1.52/test/image/im2.jpg", "title": ...

Ways to send JSON data to a FastAPI backend without relying on Swagger UI

Trying to perform a basic POST operation with FastAPI. A simple structure has been set up using BaseModel, consisting of only two attributes, name and roll. import uvicorn from fastapi import FastAPI from pydantic import BaseModel class Item(BaseModel): ...

The getInitialProps function in Next.js is not functioning properly in mobile browser environments

My app runs perfectly on desktop without any errors. However, when I switch to a mobile device, I noticed that the pages fail to trigger the getInitialProps method on the client side, only if I navigate through the Link component. This is my code: return( ...

Angular does not wait for the backend service call response in tap

Does anyone have a solution for subscribing to responses when the tap operator is used in a service? edit(status) { dataObj.val = status; // call post service with status.. this.service .update(dataObj) .pipe(takeUntil(this._n ...

How can Codeception/Selenium help in testing the tooltip or customValidity message?

I am trying to implement a feature in my Codeception scenario where I want to validate a form submission with user errors, such as confirming a wrong email address, and display a custom tooltip message in the browser. HTML <form ... > <label ...

Having trouble converting JSON to a DataSet with Json.Net

I have been attempting to parse a block of JSON using json.net (), but it keeps failing and stating that there is text after the JSON object. However, upon inspecting where the exception occurs, if (checkAdditionalContent) { if (reader.Read( ...

While attempting to scrape data, the console.log function displays the information, however it is not being returned

This code is now working perfectly! However, I am struggling to organize the data into an array of separate objects. getGAS: function(url) { var self=this; rp(options) .then(($) => { let gasset = []; $('.stations-list').each(functio ...

Ensuring the server application is up and running before initiating the mocha tests

This is similar to Ensuring Express App is running before each Mocha Test , but the proposed solution isn't effective + I am utilizing a websocket server In essence, I'm making use of a websocket framework called socketcluster and this represent ...

Contrast among 17-digit timestamps

Currently, I am dealing with timestamps in Node.js that are in the UTC+02:00 timezone. I am trying to calculate the time difference between two timestamps, each consisting of 17 digits. For instance, I have two timestamps: 20180712080000000 (YYYYMMDDHHmmss ...

I would like to exclude the item within my ng-repeat loop using ng-if

I'm attempting to utilize ng-if within ng-repeat in order to create Accordions. Depending on the condition value, I want certain items to be skipped in the ng-repeat. For example, if item.condition is true, then only display the accordion. The code b ...

The npm outdated -g command is producing an error message that states "Unable to read the length property of undefined"

I am currently facing an issue while trying to check the version status of my npm installed global packages. When I run the command npm outdated -g --depth=0 in the terminal, I encounter the following error: npm ERR! Cannot read property 'length&apos ...

Utilize jQuery to seamlessly transfer each recorded audio file from rows to corresponding input fields within the table

I have a table below with 2 rows but it can be doubled with a button (Add another Word media) and only one submit button for all rows: <tbody> <tr class="form-row dynamic-medias" id="medias-0"> <td class=&quo ...

Tips on preventing external JavaScript execution and site requests in PhantomJS

I'm currently conducting tests on a website in search of any potential issues. Just to clarify, I am utilizing phantomjs with ghostdriver in selenium through C# Everything is functioning properly, but I want to optimize the speed. After checking the ...

What could be causing the issue where only the latest data is being shown

When I use ajax to retrieve data from my database, the console.log displays all the results correctly, but in my HTML, only the last result is shown. What could be causing this issue? Any help would be appreciated! Thanks! Please keep your response simple ...