3
{
  "symbol": "BPCL",
  "series": "EQ",
  "openPrice": "1,020.00",
  "highPrice": "1,041.95",
  "lowPrice": "1,016.55",
  "ltp": "1,040.55",
  "previousPrice": "1,013.45",
  "netPrice": "2.67",
  "tradedQuantity": "3,76,694",
  "turnoverInLakhs": "3,892.87",
  "lastCorpAnnouncementDate": "13-Jul-2016",
  "lastCorpAnnouncement": "Bonus 1:1"
} 

This is sample data given in gainers.txt file i want to parse these information and store it on separate variable eg var symbol should store all the symbols in txt file so that i can process with that variables later in my code.

2 Answers 2

2

You need to add a dataType:

$(document).ready(function() {
    $.ajax({
        url : "mytext.txt",
        dataType: "text",
        success : function (data) {
            $(".text").html(data);
            var jsonData = JSON.parse(data);
        }
    });
}); 

You can use jsonData as data json object format, or use data instead for text format.

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

Comments

0

You should be able to do this using JSON parser

var a = '[{"symbol":"BPCL","series":"EQ","openPrice":"1,020.00","highPrice":"1,041.95","lowPrice":"1,016.55","ltp":"1,040.55","previousPrice":"1,013.45","netPrice":"2.67","tradedQuantity":"3,76,694","turnoverInLakhs":"3,892.87","lastCorpAnnouncementDate":"13-Jul-2016","lastCorpAnnouncement":"Bonus 1:1"}]';

var jsonData = JSON.parse(a);

alert(jsonData[0].symbol)
alert(jsonData[0].series)
alert(jsonData[0].openPrice)

etc

Comments

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.