Link to home
Start Free TrialLog in
Avatar of Seven price
Seven priceFlag for United States of America

asked on

get json value

On error I am returning json results.
var text = '{"Message":"The request is invalid.","ModelState":{"model.Email":["The Email field is required."],"model.Password":["The Password field is required."]}}';



var mytext = {"Message":"The request is invalid.","ModelState":{"":["Passwords must have at least one non letter or digit character. Passwords must have at least one lowercase ('a'-'z'). Passwords must have at least one uppercase ('A'-'Z')."]}}

Open in new window


function (error, status) {

Open in new window


I tried json.parse
Avatar of Pravin Asar
Pravin Asar
Flag of United States of America image

Your json is valid. (Use http://jsonlint.com/)

Looks like your mytext assignment has missing quote (')

When you add these quotes, you have to properly escape occurence of quotes within string.

For example:

mytext ='{"Message":"The request is invalid.","ModelState":{"Warning":["Passwords must have at least one non letter or digit character. Passwords must have at least one lowercase (\'a\'-\'z\'). Passwords must have at least one uppercase (\'A\'-\'Z\')."]}}';

 alert (mytext);
I noticed in your string, the missing element name.

"ModelState":{""


I assigned "Warning" as name.
Avatar of Seven price

ASKER

ok I know it is valid I am trying to return the value in a alert box.
What is 'function (error, status) {'

You haven't really given us a lot to go on, or indicated where you have a problem.

My guess here is that you are trying to make an AJAX request and expecting the error handler to notice when your username or password aren't valid.

If that's the case, the jQuery request will only receive the JSON data back in the success handler, not the error handler. The error handler only fires if the AJAX request failed.
Yes I know that, I set up a demo on jfiddler. being lazy today. ok
OK - In that case, do you want to give us some clue as to what your problem is, or at least what you're trying to do?

You've given us exactly 2 variable definitions and 1 function declaration. No errors, no questions, no idea as to what you need. Work with us and we can help you.
http://jsfiddle.net/sevensnake/vqbvnvh2/2/

Ok I want to get the value from result  modelstate and result2 model state. either example will work.
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I kind of figured to use a object. good job. Thanks