html.raw in jquery?

websss
websss used Ask the Experts™
on
Following on from this question
https://www.experts-exchange.com/questions/29143196/Float-array-in-c-when-passed-to-JS-it's-in-wrong-order.html?headerLink=workspace_answered_questions

I now need to
call the following

 $.ajax({
                type: "POST",
                url: "@Url.Action("CameraChange", "Home")",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                   imageDataArray = response.DataArray;
                }

Open in new window



However I've no idea how to convert to returned string
[[273.7,273.8,273.8,274.6,274.6,274,274,274.3,274........ ]]

Open in new window


to the JS object: imageDataArray

In the othe question i used @HTML.RAW, which works great and i can then access the data like
imageDataArray[x][y]

Open in new window

to get the value at that position

How would i do this in Js/Jquery?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Excatly the same way.

The returned data is an array of arrays.
imageDataArray[0][0]

Open in new window

Will give you the first value in the first array
websssCEO

Author

Commented:
I puit an alert on that code, Sometimes it seems to work, other times it just returns [

But either way, its not updating the object correctly, it doesn't seem to be an array or work with the rest of the code

this is what i see from HTML RAW, and it works fine (from initial question, this works great now)
thisWOrks
However after updating the object, it looks like this, and it doesn't work with the rest of the code
thisBreaks
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
It might be that it needs to be parse again - not sure why it would as you have specified dataType: json in your AJAX options.

Just for giggles try this

imageArray = JSON.parse(response.DataArray);

Open in new window


And then see what that gives you.

Failing that can you post a text file or similar with the results of the AJAX response.

You can get it like this

<textarea id="result"></textarea>

Open in new window


And in your AJAX Callback
$('#result').value = response.DataArray;

Open in new window

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Please post the HomeController/CameraChange method so we can see what it returns?
websssCEO

Author

Commented:
This is the code
  [HttpPost]
        public JsonResult CameraChange(string cameraId)
        {

       
            camera = process.GetCamByCamId(cameraId);
          

            var imageData = process.Process_Image_Temp_Files_OnLoad(camera).FirstOrDefault();




            return Json(imageData, JsonRequestBehavior.AllowGet);
        }

Open in new window


the bit in question is in another method and saves this as a string
pd.DataArray = JsonConvert.SerializeObject(temperatureData);
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
The code that generates it is not really in play on this one - if anything we need to see the raw response.

Did you try the JSON.parse()?
websssCEO

Author

Commented:
Thanks, JSON.parse() fixed it
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial