0

I have the following jquery function to parse the json array "projectDetail" , but when i try print the value of ApprovalDesc from the array its showing as undefined, please can i know what is the right syntax ?

function show(projectDetail) {
          var  project = projectDetail;
            $.each(project, function (i, tweet) {
                $.each(tweet.ProjectUpdates, function (i, tweet1) {
                $.each(tweet1.ProjectApproval, function (i, tweet2) {
                alert(i + ': ' + tweet2.ApprovalDesc);
               var PStatus = tweet.ApprovalDesc;
            });
        });
        });
       }

json output

{ "d" : {
      "ProjectUpdates" : { "ExceptionId" : 0,
          "ProjectApproval" : [ { "ApprovalDesc" : "ABCApproved",
                "CreatedBy" : null,
                "CreatedDate" : "/Date(-62135596800000)/", 
                "ModifiedDate" : "/Date(-62135596800000)/",
                "ApprovalDesc" : "welcome",
                "SortOrder" : 1
              } ],
          "ProjectStatusGallery" : [ { "CategoryId" : 0,
                "CreatedBy" : null,
                "CreatedDate" : "/Date(-62135596800000)/",              
                "ImageName" : "flower",
                "ImageUrl" : "D://Images",
                "ModifiedBy" : null,
                "ModifiedDate" : "/Date(-62135596800000)/",               
              },
              { "CategoryId" : 0,
                "CreatedBy" : null,
                "CreatedDate" : "/Date(-62135596800000)/",                
                "ImageName" : "flower2",
                "ImageUrl" : "D://Images",
                "ModifiedBy" : null,
                "ModifiedDate" : "/Date(-62135596800000)/"                
              }
            ]
        },
 "__type" : "sample"
    } }
0

2 Answers 2

1

welcome should be quoted as a string.

Sign up to request clarification or add additional context in comments.

Comments

0

have you called parseJSON on the json string to put it in an object? Then its easy to access, no loop required.

http://api.jquery.com/jQuery.parseJSON/

var json = $.parseJSON(your_json_string);

console.log(json.__type.sample);
console.log(json.d.ProjectUpdates.ProjectStatusGallery.ImageName);

2 Comments

it is a jquery function, sorry i should have written $.parseJSON
ok. in above json output ProjectStatusGallery is list, this list have more elements. i need to parse in $.each(). i have to take value of ImageName in each loop.how to do that one. any one can help me please. thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.