あなたは必要な文字列に元の文字列を変換するための正規表現replacemntを使用することができます。
var s='[donor="company1" web="http://company1.com" amount="5.50"];[donor="company2" web="http://company2.com" amount="40.00"]';
s='[' + s.replace(/\[/g,'{').replace(/\]/g,'}').replace(/=/g,':')
.replace(/"\s/g,'", ').replace(/{(.+?):/g,'{"$1":')
.replace(/;/g,',\r\n') + ']';
この変換の結果は、オブジェクトの配列のJSON表記であるあなたが取得したい文字列であり、 。
このJSON式を評価すると、オブジェクトの配列が得られます。
var t = eval(s);
alert(t.length); // output 2, which is the array length
alert(t[0].donor); // outputs company1, which is the donor of the first object in the array
あなたが遊ぶことができます:あなたは前のスクリプトの末尾に以下の行を追加する場合
、あなたはJSONで表現するオブジェクトが含まれている長さ2の配列を、得ることがわかります
<html>
<head>
<script type="text/javascript">
var s='[donor="company1" web="http://company1.com" amount="5.50"];[donor="company2" web="http://company2.com" amount="40.00"]';
s='[' + s.replace(/\[/g,'{').replace(/\]/g,'}').replace(/=/g,':')
.replace(/"\s/g,'", ').replace(/{(.+?):/g,'{"$1":')
.replace(/;/g,',\r\n') + ']';
var t = eval(s);
alert("Array length: " + t.length);
alert("1st object donor: " + t[0].donor);
</script>
</head>
<body>
</body>
</html>
あなたの問題は、実際にその質問とは関係ありません:とw3schools try it yourself editor .Copyで、このコードで、このコードを貼り付けます。あなたはフォーマットされていないデータの文字列を持っています。配列やオブジェクトではありません。また、javascriptが解析するものもありません。それが本当に文字列なら、それを解析する必要があります。 – elclanrs
JSONオブジェクトの配列と似ているので、実際のJSONで簡単に変換でき、JavaScriptでエバーク可能です。私の答えをチェックすることができます。 – JotaBe