文字列を配列に分解しようとしています。以下のこのコードはそれを行いますが、今度はそれをいずれかのサブ配列に分解する必要があります。
文字列とコードは次のとおりです。
$(document).ready(function() {
var content='Image{BackgroundImage: Image.gif;Position: 0, 0;Width: 320;Height: 480;}Button{BackgroundImage: Button.gif;Position: 49, 80;Width: 216;Height: 71;}Button{BackgroundImage: Button2.gif;Transition: View2;Position: 65, 217;Width: 188;Height: 134;}Label{Position: 106, 91;Width: 96;Height: 34;Text: "Button";FontSize: 32;Color: 0.12549, 0.298039, 0.364706, 1;}';
var result = content.split('}');
result.pop();// removing the last empty element
console.log(result);
for(var i=0;i<result.length;i++)
{
result[i]+='}';
console.log(result);
$('div').append('<li>' + result[i] + '</li>');
}
})
これは次のようになります。
<li>Image{BackgroundImage: Image.gif;Position: 0, 0;Width: 320;Height: 480;}</li>
<li>Button{BackgroundImage: Button.gif;Position: 49, 80;Width: 216;Height: 71;}</li>
<li>Button{BackgroundImage: Button2.gif;Transition: View2;Position: 65, 217;Width: 188;Height: 134;}</li>
<li>Label{Position: 106, 91;Width: 96;Height: 34;Text: "Button";FontSize: 32;Color: 0.12549, 0.298039, 0.364706, 1;}</li>
私が今やらなければならないことは、それをさらに分解して、{}の前に単語があるようにすることです。つまり、最初の画像の画像です。
理想的には、出力をこのようなキー/値オブジェクトにしたいと思います
{
"Controls": [{ "Image":"{BackgroundImage: Image.gif;Position: 0, 0;Width: 320;Height: 480;}",
"Button":"{BackgroundImage: Image.gif;Position: 0, 0;Width: 320;Height: 480;}",
"Button":"{BackgroundImage: Image.gif;Position: 0, 0;Width: 320;Height: 480;}",
"Label":"{BackgroundImage: Image.gif;Position: 0, 0;Width: 320;Height: 480;}", }],
}
私の主な目標は、この最後にキーまたは値のいずれかをターゲットにできるようにすることです。
どんな助けでも大歓迎です