0

How can I extract pathmp3 from blow String?

[
    {
    "id":2578774,
    "word":"apple",
    "addtime":"2013-11-04 21:40:05",
    "hits":6796,
    "username":"JerrySun",
    "sex":"m",
    "country":"United States",
    "code":"en",
    "langname":"English",
    "pathmp3":"http:\/\/apifree.forvo.com\/audio\/3l2h333f1p3d1h2a363f2j3b2h2j282e3f373m2b3f2k1g31231n3m3i3l331n2637361i3g393c293j243i3l2c3o341b2p291j2k1n1l1o3m233p2e1g1h2i343m25_2925241j3a1j3f342e232c3k2k212n2i29263p352i3n1t1t",
    "pathogg":"http:\/\/apifree.forvo.com\/audio\/28313h382e3j2g3k3k231b311j3k39281l1h1m1g2d1h3m2h3g3k1o2h3n2m273325332l3e331g2n2j2l2k293b3d3k2f3a322k2l1p2521232a232a2l2n1l2p2q3l_2i253a2o1f233626273i3d2e2k243j231j243m2a28371t1t",
    "rate":5,
    "num_votes":5,
    "num_positive_votes":5
    }
];
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
MAB313
  • 1
  • 3
  • 1
    http://stackoverflow.com/questions/4935632/parse-json-in-javascript – seenukarthi Dec 07 '14 at 10:57
  • Thank you for your Update! I ask this question cuz here i take this string from server. in those answer that you recommended , the user send Ajax with callback element that make it easy to read answer. but i made this in C# and send the string to client. then I try to read String with jquery. – MAB313 Dec 08 '14 at 12:17
  • In that case youcan use `JSON.parse(string);` to convert the string to JSON object. – seenukarthi Dec 08 '14 at 12:20
  • Or Use Xml and Send answer to client side ! Simple, Faster and Better Performance. Thank You . :-) – MAB313 Dec 08 '14 at 12:26

2 Answers2

1

You can access this value with arr[0].pathmp3

var arr= [
    {
    "id":2578774,
    "word":"apple",
    "addtime":"2013-11-04 21:40:05",
    "hits":6796,
    "username":"JerrySun",
    "sex":"m",
    "country":"United States",
    "code":"en",
    "langname":"English",
    "pathmp3":"http:\/\/apifree.forvo.com\/audio\/3l2h333f1p3d1h2a363f2j3b2h2j282e3f373m2b3f2k1g31231n3m3i3l331n2637361i3g393c293j243i3l2c3o341b2p291j2k1n1l1o3m233p2e1g1h2i343m25_2925241j3a1j3f342e232c3k2k212n2i29263p352i3n1t1t",
    "pathogg":"http:\/\/apifree.forvo.com\/audio\/28313h382e3j2g3k3k231b311j3k39281l1h1m1g2d1h3m2h3g3k1o2h3n2m273325332l3e331g2n2j2l2k293b3d3k2f3a322k2l1p2521232a232a2l2n1l2p2q3l_2i253a2o1f233626273i3d2e2k243j231j243m2a28371t1t",
    "rate":5,
    "num_votes":5,
    "num_positive_votes":5
    }
];

alert(arr[0].pathmp3);
baao
  • 71,625
  • 17
  • 143
  • 203
1

It seems you have one Object in your String which is actually an Array.

Simply do alert(myString[0].pathmp3);

myString[0] will access the first (and only) object, and .pathmp3 appended to it will access the pathmp3 property of that object.

Working Code Snippet:

var myString= [
    {
    "id":2578774,
    "word":"apple",
    "addtime":"2013-11-04 21:40:05",
    "hits":6796,
    "username":"JerrySun",
    "sex":"m",
    "country":"United States",
    "code":"en",
    "langname":"English",
    "pathmp3":"http:\/\/apifree.forvo.com\/audio\/3l2h333f1p3d1h2a363f2j3b2h2j282e3f373m2b3f2k1g31231n3m3i3l331n2637361i3g393c293j243i3l2c3o341b2p291j2k1n1l1o3m233p2e1g1h2i343m25_2925241j3a1j3f342e232c3k2k212n2i29263p352i3n1t1t",
    "pathogg":"http:\/\/apifree.forvo.com\/audio\/28313h382e3j2g3k3k231b311j3k39281l1h1m1g2d1h3m2h3g3k1o2h3n2m273325332l3e331g2n2j2l2k293b3d3k2f3a322k2l1p2521232a232a2l2n1l2p2q3l_2i253a2o1f233626273i3d2e2k243j231j243m2a28371t1t",
    "rate":5,
    "num_votes":5,
    "num_positive_votes":5
    }
];

alert(myString[0].pathmp3);
Rahul Desai
  • 15,242
  • 19
  • 83
  • 138